‎2007 May 02 9:33 AM
Hello,
I have to replace the character ' in a string, but the compiler doesn't allow me to use something like this:
REPLACE ALL OCURRENCES ''' in: local_string with space.
Does anybody know, how to do it?
Cheers
Hercules
‎2007 May 02 9:35 AM
Hi
To replace a string in a field with a different string, use the REPLACE statement.
REPLACE <str1> WITH <str2> INTO <c> [LENGTH <l>].
The statement searches the field <c> for the first occurrence of the first <l> positions of the pattern <str1>. If no length is specified, it searches for the pattern <str1> in its full length.
Then, the statement replaces the first occurrence of the pattern <str1> in field <c> with the string <str2>. If a length <l> was specified, only the relevant part of the pattern is replaced.
Regards
Sudheer
‎2007 May 02 9:35 AM
Hi
To replace a string in a field with a different string, use the REPLACE statement.
REPLACE <str1> WITH <str2> INTO <c> [LENGTH <l>].
The statement searches the field <c> for the first occurrence of the first <l> positions of the pattern <str1>. If no length is specified, it searches for the pattern <str1> in its full length.
Then, the statement replaces the first occurrence of the pattern <str1> in field <c> with the string <str2>. If a length <l> was specified, only the relevant part of the pattern is replaced.
Regards
Sudheer
‎2007 May 02 9:36 AM
Hi
To replace a string in a field with a different string, use the REPLACE statement.
<b>REPLACE <str1> WITH <str2> INTO <c> [LENGTH <l>].</b>
The statement searches the field <c> for the first occurrence of the first <l> positions of the pattern <str1>. If no length is specified, it searches for the pattern <str1> in its full length.
Then, the statement replaces the first occurrence of the pattern <str1> in field <c> with the string <str2>. If a length <l> was specified, only the relevant part of the pattern is replaced.
If the return code value of the system field SY-SUBRC is set to 0, this indicates that <str1> was found in <c> and replaced by <str2>. A return code value other than 0 means that nothing was replaced. <str1>, <str2>, and <len> can be variables.
DATA: T(10) VALUE 'abcdefghij',
STRING LIKE T,
STR1(4) VALUE 'cdef',
STR2(4) VALUE 'klmn',
STR3(2) VALUE 'kl',
STR4(6) VALUE 'klmnop',
LEN TYPE I VALUE 2.
STRING = T.
WRITE STRING.
REPLACE STR1 WITH STR2 INTO STRING.
WRITE / STRING.
STRING = T.
REPLACE STR1 WITH STR2 INTO STRING LENGTH LEN.
WRITE / STRING.
STRING = T.
REPLACE STR1 WITH STR3 INTO STRING.
WRITE / STRING.
STRING = T.
REPLACE STR1 WITH STR4 INTO STRING.
WRITE / STRING.
<b>The output appears as follows:
abcdefghij
abklmnghij
abklmnefgh
abklghij
abklmnopgh</b>
Note how, in the last line, the field STRING is truncated on the right. The search pattern 'cdef' of length 4 is replaced by 'klmnop' of length 6. Then, the rest of the field STRING is filled up to the end of the field.
Regards Rk
‎2007 May 02 9:38 AM
use TRANSLATE
TRANSLATE local_string USING '` '. "--> Use single quote above TAB key in keyboard
‎2007 May 02 9:39 AM
HI Hercules,
copy this:
<b>REPLACE ALL OCURRENCES of `'` in local_string with space.</b>
Note that the QUOTE symbol that i have used are not the normal quotes.
It is the QUOTE symbol that is above the TAB key in the keyboard.
Regards,
Ravi
‎2007 May 02 9:52 AM
Hi,
Just check out this code if it helps you:
DATA: v_char(60) VALUE 'India has ''greate'' history and ''rich''
heritage'.
TRANSLATE v_char USING ''' '.
condense v_char.
WRITE: v_char.
Regards,
Varun.
‎2007 May 02 9:58 AM
handling single quote
option 1.
<b> `'`</b> single quote surronded by the symbole in key to the left of number 1 in your key board. (sorry dont know the name of the symbol)
option two
'''' (thats four single quotes)