Solved

Find and replaceing characters in a character string.

Posted on 2008-06-17
5
1,244 Views
Last Modified: 2013-11-25
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.  
0
Comment
Question by:dman462008
  • 2
  • 2
5 Comments
 
LVL 18

Expert Comment

by:daveslash
ID: 21806270

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
0
 
LVL 18

Expert Comment

by:daveslash
ID: 21806362

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

0
 
LVL 27

Expert Comment

by:tliotta
ID: 21807081
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
0
 
LVL 16

Expert Comment

by:theo kouwenhoven
ID: 21811380
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

0
 
LVL 16

Accepted Solution

by:
theo kouwenhoven earned 50 total points
ID: 21811399
Hi dman462008,

Or a complete callable program that we use (see snippet)
#From and #To are 26 positions, because we use it to put strings from mixed case to upper case :)

Good Luck,
Murph
C     #FROM:#TO     XLATE     #INP          #OUT                     
C                   SETON                                        LR  
                                                                     
C     *ENTRY        PLIST                                            
C                   PARM                    #From            26      
C                   PARM                    #To              26      
C                   PARM                    #Inp            256      
C                   PARM                    #Out            256      

Open in new window

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
c# call as400 program with integer parameters 5 581
iSeries Bath SFTP CL Program Problem 6 476
Webservice response iSeries 1 49
BRMS - TSM API DSMERROR.LOG 5 45
Starting your own business is always a daunting process, and for most people it is brand new experience. Avoid the common pitfalls by following these tips to start on the road to success.
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question