2014 Jan 07 9:33 AM
Hi all.
I am having a problem that I am trying to replace special characters
in a string with hash. in 4.5 there is no function module to resolve this issue,
I have checked.
We do not know the complete set of special characters., even if we did,
I want a flexible way to replace the special characters in a string..
I tried one approach, to find special characters in string and
use offset to replace them with hash. but 4.5 does NOT allow
use of variable offset, only constant.
here is the code :
do total_length times.
lw_position = sy-index - 1.
concatenate 't_bkpf-xblnr+' lw_position '(1)'
into lc_special_char.
if lc_special_char na c_valid_chars.
lw_special_char = lc_special_char.
replace lw_special_char into lc_special_char
with lv_space.
endif.
enddo.
Any solutions?
Thanks,
Regards,
Nirav
Hi Manu,
I cannot use this because in t_bkpf-xblnr+lw_position(1)
I cannot use lw_position here since it is a variable. I can
only use constant in 4.5
Nirav
2014 Jan 07 9:49 AM
Hi,
Not sure to get the issue...
Why using that concatenate statement?
Why not simply:
IF t_bkpf-xblnr+lw_position(1) NA c_valid_char.
REPLACE...
ENDIF.
Br,
Manu.
2014 Jan 07 9:50 AM
Please search for regular experisions/REGEX or check program dEMO_REGEX for the same
Nabheet
2014 Jan 07 10:15 AM
2014 Jan 07 11:19 AM
2014 Jan 08 1:04 AM
Hi Manu,
I cannot use this because in t_bkpf-xblnr+lw_position(1)
I cannot use lw_position here since it is a variable. I can
only use constant in 4.5
Nirav
2014 Jan 08 8:26 AM
Too bad...
So the only way I can see so far is by shifting your string char by char (SHIFT ... LEFT BY 1 PLACES) and checking t_bkpf-xblnr+0(1)...
Cheers,
Manu.
2014 Jan 07 10:01 AM
Hi Nirav,
Please check as below.
IF 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_' CS field+0(1).
else.
Write: / 'special characters are there'.
endif.
You can check word by word.
Arivazhagan S
2014 Jan 07 10:16 AM
Try like this..
DATA:string TYPE string.
string = './&^%&^%!@&%FARID^%^%@%!HASAN'.
REPLACE ALL OCCURRENCES OF REGEX '[^[:alnum:]]' IN string WITH `#` .
WRITE string.
2014 Jan 07 11:17 AM
2014 Jan 08 1:08 AM
Guys...I have checked the 4.5 ..there is NO Function module to solve this...
Also I cannot use REGEX.
Any other solution?
Thanks,
Nirav
2014 Jan 08 11:08 AM
data : string type string.
string = 'agkle*(&#kljabg23984903*%)(2k0j'.
data len type i.
data : ofs type i, c.
len = strlen( string ).
TRANSLATE string to UPPER CASE.
ofs = 0.
write : string.
do len times.
c = string+ofs(1).
if c CN '1234567890' and c CN sy-abcde.
replace all OCCURRENCES OF c in string with '#' .
endif.
add 1 to ofs.
enddo.
write 😕 string.
2014 Jan 08 5:08 AM
Hi,
pls check this
DATA:
v_count TYPE i,
v_namelen TYPE i,
lv_variable TYPE string VALUE 'KIRAN!$%^'.
v_count = 0.
v_namelen = strlen( lv_variable ).
DO v_namelen TIMES.
IF lv_variable+v_count(1) NA sy-abcde ."or lv_variable+v_count(1) NA space .
REPLACE lv_variable+v_count(1) WITH '#' INTO lv_variable.
endif.
v_count = v_count + 1.
ENDDO.
2014 Jan 08 8:33 AM
Hi Nirav
Can you please add here one example with your inputs and expected output..?
Nabheett
2014 Jan 08 10:16 AM
Hi Nirav,
You could potentially use the "SEARCH" statement to record all positions with special characters in a table, after which you could loop at the table and replace all positions with '#'.
This still does not seem like the best solutions, but maybe it should be considered.
Also have a look at the sap help documentation on string operations. You might find some good alternatives.
2021 Dec 28 11:57 AM
replace all occurrences of REGEX '(#)' in bseg-sgtxt with space.
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |