2008 Jun 26 2:37 PM
Hi friends,
I am facing a issue where i need to replace " with "" at all occurance in a string.
My server is not supporting the Statement REPLACE AT ALL OCCURANCES statement.
We tried with Replace statement as it is replacing the first occurance of " in the word. Ineed to replace every occurance.
Example : if the string is "My""Name"
Then expected out put is """My""""Name"""
Help will be appreciated...
Please help me in this regard...
Regards,
aanand
2008 Jun 26 2:49 PM
2008 Jun 26 2:42 PM
hiiii
it is working..
use like below
DATA : w_a(30) TYPE c VALUE '01&34&6abcd',
w_rule(30) TYPE c value 'X',
w_string1(50) TYPE c.
w_string1 = w_a.
replace all occurrences of '&' in w_string1 with w_rule.
write: w_string1.regards
twinkal
2008 Jun 26 2:44 PM
Do you mean you are on an earlier version that doesn't support REPLACE ALL OCCURENCES?
You could REPLACE to something other than ", for example §. Then go through the string again, replacing § with "".
E.g.
"text" goes to §text§ goes to ""text""
You have to put the REPLACE in a loop to get all occurences.
matt
2008 Jun 26 2:45 PM
Are you checking on the first character of the string? You could do a check using LIKE
l_string type C
l_st1 type l_string
l_st2 type l_string
l_var type C VALUE '"'
If l_string(1) like l_var.
Split l_string AT <where needs split> into l_st1 l_st2.
Concatenate l_st1 ' ' l_st2 into l_string.
Endif.
You can alson concatentate variables and separate by SPACE or SEP. Sep will place a separator between each variable. Hope this helps or gives ya some direction to go with.
Regards,
C
2008 Jun 26 2:45 PM
Thank you for replying...
but my server version is not supporting
"replace all occurrences of " statement...
2008 Jun 26 2:49 PM
You do realise I'm suggesting using the old form of replace:
REPLACE sub_string WITH new INTO dobj
[IN {BYTE|CHARACTER} MODE]
[LENGTH len]. NOT replace all occurences...
matt
2008 Jun 26 2:48 PM
Hello.
Try this code:
DATA: var1 TYPE string VALUE '"My""Name"',
var2 TYPE string,
lenght TYPE i.
DATA: pos TYPE i.
CLEAR pos.
lenght = STRLEN( var1 ).
DO lenght TIMES.
IF var1+pos(1) EQ '"'.
CONCATENATE var2 var1+pos(1) var1+pos(1) INTO var2.
ELSE.
CONCATENATE var2 var1+pos(1) INTO var2.
ENDIF.
ADD 1 TO pos.
ENDDO.
WRITE var2.
Regards.
Valter Oliveira.
2008 Jun 26 2:49 PM
2008 Jun 26 2:50 PM
>
> You may try to combine TRANSLATE and REPLACE to do the job
> - TRANSLATE " to a character, e.g. # (USING ''#) , you are sure is not in the string
> - DO/REPLACE # WITH ""/ENDDO until SY-SUBRC is not zero
> Regards
I should have mentioned that - it's the solution I used to use before REPLACE got updated. Nice one.
2008 Jun 26 2:49 PM
check this
REPORT z_sdn.
data text(30).
text = '"My""Name"'.
replace all occurrences of '"' in text with '""'.
write text.
2008 Jun 26 2:59 PM
2008 Jul 15 11:27 AM