Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Find and replaceing characters in a character string.

Posted on 2008-06-17
5
Medium Priority
?
1,250 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 200 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

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

Read on to get a few ideas on how to promote your next corporate event.
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

718 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