Solved

Find and replaceing characters in a character string.

Posted on 2008-06-17
5
1,248 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Getting to know the threat landscape in which DDoS has evolved, and making the right choice to get ourselves geared up to defend against  DDoS attacks effectively. Get the necessary preparation works done and focus on Doing the First Things Right.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

636 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