06-13-2011 7:42 AM
Hi Friends,
I would like to Replace the Charecter values with numeric value in my string.
Exp : first in my string I am having the value like this : 'ABCD1234' ( may be any char and num values ), and I want too get it by '99991234'.
I mean How to replace the char values into numeric in my string?
Thanks,
Sridhar
06-13-2011 7:51 AM
Hi,
Is it fixed that 1st 4 characters are char and last 4 numeric?
Then use offset and extract both of them in two different variable.
Then replace 1st one by your numeric data (9999).
And concatenate back into a single variable.
06-13-2011 8:07 AM
Hi,
The charecters may come in anywhere...in my string.
Exp: ABCD1234, 1A2B3SS....so on.....I need to remove all the charecters from the string and need to replace with 9 any my string.
I was used the statement REGEX but it is giving me the syntax error " The word REGEX is reserved".
06-13-2011 8:13 AM
Hi,
use Translate keyword
PARAMETERS : l_st TYPE string.
TRANSLATE l_st USING 'A9B9C9D9E9F9G9H9I9J9K9L9M9N9O9P9Q9R9S9T9U9V9W9X9Y9Z9'.
WRITE L_ST.
Regards,
Dhina..
06-13-2011 8:18 AM
Hi Dhina,
This addresses only upper case, doesn't address lower case or special characters,
i guess using the regular expression in this case would be better (/D).
Regards,
Chen
06-13-2011 8:39 AM
Thanks Dina....Converted my string to Upper case...and used the translate statement...
Problem solved.
To remove the spl chars I was used the FM ES_REMOVE_SPECIAL_CHARACTER.
Thanks,
Sridhar
06-13-2011 8:56 AM
Hi,
you can do as what sap_wiz has suggested else you can try as below code for your reference.
REPORT ztest_1_um2.
DATA: text1 TYPE string VALUE 'ABCD1234',
sub_string TYPE c ,
new TYPE string VALUE '9',
id TYPE i,
offset TYPE i.
id = STRLEN( text1 ).
*
DO id TIMES.
if sy-index = 1.
iF sy-abcde CS text1(1).
sub_string = text1(1).
REPLACE sub_string WITH new INTO text1.
WRITE:/ text1.
ELSE.
CONTINUE.
ENDIF.
ELSEif sy-index < id.
offset = sy-index - 1.
IF sy-abcde CS text1+offset(1).
sub_string = text1+offset(1).
REPLACE sub_string WITH new INTO text1.
WRITE:/ text1.
ELSE.
CONTINUE.
ENDIF.
endif.
ENDDO.
Regards,
Umang Mehta
06-13-2011 8:57 AM
Hi Sridhar,
Try the below string with your code,
ASFDKASFD(&^(&#@^(@*#&ASDKJFHKASJFH234124791124
Regards,
Chen
06-13-2011 7:54 AM
hi ,
Please tell what will be possible input and what should be output .
all possible combination .
regards
Deepak.
06-13-2011 8:01 AM
HI ,
YOU CAN ALSO USE
DATA : TEST(8) TYPE C VALUE 'ABCD1234' .
REPLACE ALL OCCURRENCES OF REGEX 'ABCD' IN TEST WITH '9999'.
WRITE : TEST.
Regards
Deepak.
06-13-2011 8:06 AM
Hi Sridhar,
I would like to Replace the Charecter values with numeric value in my string.
Exp : first in my string I am having the value like this : 'ABCD1234' ( may be any char and num values ), and I want too get it by '99991234'.
So, if i understand you correctly, you want to replace all characters in a string with 9 as in the above example, irrespective of position of the character, if so try with the below code.
DATA: l_str TYPE string.
l_str = 'ASKHSIUDNSBDKJSDH124312431243124saasdfsf'.
REPLACE ALL OCCURRENCES OF REGEX '\D' IN l_str WITH '9'.
IF sy-subrc EQ 0.
WRITE: l_str. "Result will be 9999999999999999912431243124312499999999
ENDIF.
Regards,
Chen
Edited by: Chen K V on Jun 13, 2011 12:36 PM