Solved

Find and replaceing characters in a character string.

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

A safe way to clean winsxs folder from your windows server 2008 R2 editions
Is your company's data protection keeping pace with virtualization? Here are 7 dynamic ways to adapt to rapid breakthroughs in technology.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now