Solved

Find and replaceing characters in a character string.

Posted on 2008-06-17
5
1,245 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 18

Expert Comment

by:Dave Ford
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:Dave Ford
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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
monitoring is IP address Establish connection or not on iSeries host 4 139
XML response optional elements 12 80
RUNRMTCMD from AS/400 13 131
iSeries Backup 3 64
By reading this blog, MSPs will gain insight into how to improve communications with their clients as well as establish a more profitable business.
The goal of this blog is to: > note what has impeded us from reaching effective life on-call > provide 3 steps to mastering life on-call > highlight what will be achieved with effective life on-call
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

752 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