SQL supports regular expressions, so it should be possible with an REGEX_REPLACE to replace or remove all unwanted characters:

The following expression will remove all characters that are neither digits nor lowercase characters and none of the characters </>.
RegexP_Replace(Trim(YourColumn), '[^a-z0-9<\>]', '')

So it should be possible to use this expression in an Update or Set statement:

Update YourFile
Set YourColumn = RegexP_Replace(Trim(YourColumn), '[^a-z0-9<\>]', '')

Exec SQL Set :YourIFSFile = RegexP_Replace(Trim(:YourIFSFile), '[^a-z0-9<\>]', '')

Mit freundlichen Grüßen / Best regards

Birgitta Hauser

"Shoot for the moon, even if you miss, you'll land among the stars." (Les Brown)
"If you think education is expensive, try ignorance." (Derek Bok)
"What is worse than training your staff and losing them? Not training them and keeping them!"
„Train people well enough so they can leave, treat them well enough so they don't want to.“ (Richard Branson)


-----Original Message-----
From: RPG400-L <rpg400-l-bounces@xxxxxxxxxxxxxxxxxx> On Behalf Of Bob Mircetic via RPG400-L
Sent: Donnerstag, 17. Januar 2019 02:20
To: RPG programming on the IBM i (AS/400 and iSeries) <rpg400-l@xxxxxxxxxxxxxxxxxx>
Cc: Bob Mircetic <bobmircetic@xxxxxxxxx>
Subject: Re: Replace character in a IFS file

Thanks to all for sharing this, this is fantastic!

In my case, I’d like to use this to create a process to remove all erroneous characters from xml files we receive. However, I don’t believe I can identify in advance all the characters we’d like to remove. I can, however, identify the characters I want to keep.

Is it possible to somehow pass into that 'From Value’ parameter a NOT condition? Ideally, I’d like to be able to say if it’s NOT a-z, 0-9, <, /, >, etc, then replace it with ‘'.

I’ve tried sneaking in a NOT LIKE or NOT IN there, but I’m not having any success. Is what I’m attempting even possible?

Thanks,
Bob




On Jan 16, 2019, at 7:47 AM, Birgitta Hauser <Hauser@xxxxxxxxxxxxxxx> wrote:

It can handle everything that SQL can handle.

Mit freundlichen Grüßen / Best regards

Birgitta Hauser

"Shoot for the moon, even if you miss, you'll land among the stars."
(Les Brown) "If you think education is expensive, try ignorance."
(Derek Bok) "What is worse than training your staff and losing them? Not training them and keeping them!"
„Train people well enough so they can leave, treat them well enough so
they don't want to.“ (Richard Branson)


-----Original Message-----
From: RPG400-L <rpg400-l-bounces@xxxxxxxxxxxxxxxxxx> On Behalf Of
Justin Taylor
Sent: Mittwoch, 16. Januar 2019 14:51
To: RPG programming on the IBM i (AS/400 and iSeries)
<rpg400-l@xxxxxxxxxxxxxxxxxx>
Subject: RE: Replace character in a IFS file

I really like that! Can it handle hex values?



-----Original Message-----
From: Birgitta Hauser [mailto:Hauser@xxxxxxxxxxxxxxx]
Sent: Wednesday, January 16, 2019 12:18 AM
To: 'RPG programming on the IBM i (AS/400 and iSeries)'
<rpg400-l@xxxxxxxxxxxxxxxxxx>
Subject: RE: Replace character in a IFS file

Quick and easy solution with embedded SQL:

DCL-S FromIFSFile SQLTYPE(CLOB_File);
DCL-S ToIFSFile SQLTYPE(CLOB_File);
/--------------------------------------------------------------------------------------------------------
FromIFSFile_Name = '/home/YourDir/MyIFSFile.txt';
FromIFSFile_NL = %Len(%Trim(FromIFSFile_Name));
FromIFSFile_FO = SQFRD; //Read Only

ToIFSFile_Name = '/home/YourDir/MyIFSFile.txt';
ToIFSFile_NL = %Len(%Trim(ToIFSFile_Name));
ToIFSFile_FO = SQFOVR; //Replace
Exec SQL Set :ToIFSFile = Replace(:FromIFSFile, 'FromValue', 'ToWhatever');
//Handle SQLCODE

*InLR = *On;

Mit freundlichen Grüßen / Best regards

Birgitta Hauser

"Shoot for the moon, even if you miss, you'll land among the stars." (Les Brown) "If you think education is expensive, try ignorance." (Derek Bok) "What is worse than training your staff and losing them? Not training them and keeping them!"
„Train people well enough so they can leave, treat them well enough so
they don't want to.“ (Richard Branson)


--
This is the RPG programming on the IBM i (AS/400 and iSeries)
(RPG400-L) mailing list To post a message email:
RPG400-L@xxxxxxxxxxxxxxxxxx To subscribe, unsubscribe, or change list
options,
visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives at https://archive.midrange.com/rpg400-l.

Please contact support@xxxxxxxxxxxx for any subscription related questions.

Help support midrange.com by shopping at amazon.com with our affiliate
link: https://amazon.midrange.com

--
This is the RPG programming on the IBM i (AS/400 and iSeries)
(RPG400-L) mailing list To post a message email:
RPG400-L@xxxxxxxxxxxxxxxxxx To subscribe, unsubscribe, or change list
options,
visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives at
https://archive.midrange.com/rpg400-l.

Please contact support@xxxxxxxxxxxx for any subscription related questions.

Help support midrange.com by shopping at amazon.com with our affiliate
link: https://amazon.midrange.com

--
This is the RPG programming on the IBM i (AS/400 and iSeries) (RPG400-L) mailing list To post a message email: RPG400-L@xxxxxxxxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives at https://archive.midrange.com/rpg400-l.

Please contact support@xxxxxxxxxxxx for any subscription related questions.

Help support midrange.com by shopping at amazon.com with our affiliate link: https://amazon.midrange.com


This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2019 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].