‎2009 May 29 11:35 AM
hi..
I want to convert all all commas with in quotes in a string to a different symbol, say a hash. I cannot arrive at the code to do the same. Can anyone help.
Eg : input = ' 5646," Name1, Name2 ", 234324 ," comp name , city " , 435345 '.
Output should be ' 5646," Name1# Name2 ", 234324 ," comp name # city " , 435345 '.
Is this possible ?
‎2009 May 29 11:51 AM
same as some of our friend told...
DATA:in_put TYPE string.
in_put = '5646," Name1, Name2 ", 234324 ," comp name , city " , 435345'.
write : / in_put.
REPLACE ALL OCCURRENCES OF ',' IN in_put WITH '#'.
WRITE: / in_put.
even though if u are not satisfied...... U need to loop at the string "in_put "...
its like...
data: b type int4.
b = strlen( a ).
do b times.
if a+k(1) = '"'.
x+k(1) = '!'.
so on...
enddo.
‎2009 May 29 11:36 AM
‎2009 May 29 11:38 AM
how can i use all occurrences, i tried it initially and it doesn give the output. plz note the string doesnot have a definite pattern, i just want to replace all commas within quotes.
‎2009 May 29 11:37 AM
HI,
Try this
REPLACE ALL OCCURRENCES OF ',' IN P_STRING WITH '#'.
‎2009 May 29 11:38 AM
‎2009 May 29 11:39 AM
Hi,
Use this logic,
loop at itab.
if itab-field CO '+-*/$@^&()<>&~.!,' .
replace all occurrences of ',' in itab-field with '#'.
write: / itab-field.
endif.
endloop.Regards,
Nikhil.
Edited by: Nikhil Kanegaonkar on May 29, 2009 12:40 PM
Edited by: Nikhil Kanegaonkar on May 29, 2009 12:41 PM
‎2009 May 29 11:39 AM
hi,
DATA:in_put TYPE string.
in_put = '5646," Name1, Name2 ", 234324 ," comp name , city " , 435345'.
REPLACE ALL OCCURRENCES OF ',' IN in_put WITH '#'.
WRITE:in_put.
‎2009 May 29 11:43 AM
do u know the specific number of quotes u will get in the string?
if yes..
then split the string at "
then replace use replace all occurrences of ',' with '#' on those parts u need.
then concatenate again.
‎2009 May 29 11:47 AM
‎2009 May 29 11:50 AM
‎2009 May 29 11:51 AM
same as some of our friend told...
DATA:in_put TYPE string.
in_put = '5646," Name1, Name2 ", 234324 ," comp name , city " , 435345'.
write : / in_put.
REPLACE ALL OCCURRENCES OF ',' IN in_put WITH '#'.
WRITE: / in_put.
even though if u are not satisfied...... U need to loop at the string "in_put "...
its like...
data: b type int4.
b = strlen( a ).
do b times.
if a+k(1) = '"'.
x+k(1) = '!'.
so on...
enddo.
‎2009 May 29 12:38 PM
Thanks Kiran,
tedious but the best option is this one.
itab-rec = ' 5646," Name1, Name2 ", 234324 ," comp name , city " , 435345 '.
append itab.
loop at itab.
length = strlen( itab-rec ).
do length times.
if itab-rec+i(1) = '"'.
flag = flag + 1.
endif.
if itab-rec+i(1) = ','.
flag2 = flag mod 2.
if flag2 <> 0.
itab-rec+i(1) = '#'.
modify itab transporting rec.
endif.
endif.
i = i + 1.
enddo.
‎2009 May 29 12:42 PM
‎2009 May 29 12:43 PM
‎2009 May 29 12:34 PM
Hi,
Try this.
DATA:in_put TYPE string,
var1 TYPE string,
var2 TYPE string,
var3 TYPE string,
var4 TYPE string,
var5 TYPE string,
out_put TYPE string.
DATA:len1 TYPE i.
in_put = '5646," Name1, Name2 ",234324 ," comp name , city ",435345'.
SPLIT in_put AT '"' INTO var1 var2 var3 var4 var5.
len1 = strlen( var1 ).
len1 = len1 - 1.
IF var1+len1(1) NE ',' AND var1+0(1) NE ','.
REPLACE ALL OCCURRENCES OF ',' IN var1 WITH '#'.
ENDIF.
len1 = strlen( var2 ).
len1 = len1 - 1.
IF var2+len1(1) NE ',' AND var2+0(1) NE ','.
REPLACE ALL OCCURRENCES OF ',' IN var2 WITH '#'.
ENDIF.
len1 = strlen( var3 ).
len1 = len1 - 1.
IF var3+len1(1) NE ',' AND var3+0(1) NE ','.
REPLACE ALL OCCURRENCES OF ',' IN var3 WITH '#'.
ENDIF.
len1 = strlen( var4 ).
len1 = len1 - 1.
IF var4+len1(1) NE ',' AND var4+0(1) NE ','.
REPLACE ALL OCCURRENCES OF ',' IN var4 WITH '#'.
ENDIF.
len1 = strlen( var5 ).
len1 = len1 - 1.
IF var5+len1(1) NE ',' AND var5+0(1) NE ','.
REPLACE ALL OCCURRENCES OF ',' IN var5 WITH '#'.
ENDIF.
CONCATENATE var1 '"' var2 '"' var3 '"' var4 '"' var5 INTO out_put.
WRITE: out_put.