Link to home
Start Free TrialLog in
Avatar of dman462008
dman462008

asked on

Find and replaceing characters in a character string.

I am trying to develop a routine in RPG to search a string for double quotes and replace the character with a single quote.  I will be doing this for several different variables.  
Avatar of Member_2_2484401
Member_2_2484401
Flag of United States of America image


IMHO, the easiest way to do that is to use SQL's "translate" function. You could embed the SQL in your RPG if you like.

Give me a couple minutes, and I'll whip up an example.

-- DaveSlash

Here you go:
create table deleteme (
  avc varchar(30)
)
 
insert into  deleteme
values('this " has " quotes')
 
select avc
from   deleteme
 
AVC
---
this " has " quotes
 
update deleteme
set    avc = translate(avc, '''', '"')
 
select avc
from   deleteme
 
AVC
---
this ' has ' quotes
 
 
HTH,
DaveSlash

Open in new window

Avatar of Member_2_276102
Member_2_276102

dman462008:

The way to do this will depend on (1) whether the SQL Dev Kit is installed or not, (2) what version/release of RPG you're running, and (3) whether this is RPG IV (ILE) or RPG/400 (OPM).

It _might_ depend on what your programming background is as well. Are you an experienced RPG programmer? Would you prefer binding some C library functions in rather than staying strictly with RPG op-codes? (ILE RPG lets you use the same functions that C can call.)

Can you elaborate?

Tom
Hi dman462008,

The RPG solution, sure no problem the XLATE can do that.
See Snippet

Regards,
Murph


D #FROM           C                   CONST('"')
D #TO             C                   CONST('''')
C     #FROM:#TO     XLATE     #INP          #OUT 

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Theo Kouwenhoven
Theo Kouwenhoven
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial