Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

sample code to identify special characters in a string

Former Member
0 Likes
1,547

Hi,

I need to identify special characters in a string.... could anybody send me some code please.......

Thanks,

Best regards,

Karen

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
983

data: str(100) type c.

data: str_n type string.

data: str_c type string.

data: len type i.

data: ofst type i.

str = '#ABCD%'.

len = strlen( str ).

do.

if ofst = len.

exit.

endif.

if str+ofst(1) co sy-abcde.

concatenate str_c str+ofst(1) into str_c.

else.

concatenate str_n str+ofst(1) into str_n.

endif.

ofst = ofst + 1.

enddo.

write:/ str.

write:/ str_c.

write:/ 'spacial chracter',20 str_n.

Function module <b>SF_SPECIALCHAR_DELETE</b> <b>DX_SEARCH_STRING</b>

l_address1 = i_adrc-street.

CHECK NOT L_ADDRESS1 IS INITIAL.

len = STRLEN( l_address1 ).

do len times.

if not l_address1+l(1) ca

'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 '.

  • if i_adrc-street+l(1) CO sy-abcde.

  • elseif i_adrc-street+l(1) CO L_NUMCHAR.

exit.

endif.

l = l + 1.

enddo.

data : spchar(40) type c value '~!@#$$%^&()?...'etc.

data :gv_char .

data:inp(20) type c.

take the string length .

len = strlen (i/p).

do len times

MOVE FNAME+T(1) TO GV_CHAR.

IF gv_char CA spchar.

MOVE fnameT(1) TO inp2T(1).

ENDIF.

T = T + 1.

enddo.

REPORT ZEX4 .

PARAMETERS: fname LIKE rlgrap-filename .

DATA: len TYPE i,

T TYPE I VALUE 0,

inp(20) TYPE C,

inp1(20) type c,

inp2(20) type c,

inp3(20) type c.

DATA :gv_char.

data : spchar(20) type c value '#$%^&*()_+`~'.

START-OF-SELECTION.

CONDENSE fname.

len = strlen( fname ).

  • WRITE:/ len.

DO len TIMES.

MOVE FNAME+T(1) TO GV_CHAR.

IF gv_char ca spchar.

MOVE fnameT(1) TO inpT(1).

ENDIF.

T = T + 1.

ENDDO.

CONDENSE INP.

write:/ 'Special Characters :', inp.

Rewards if useful..........

Minal

6 REPLIES 6
Read only

former_member188827
Active Contributor
0 Likes
983

try fm

CHECK_STRING_SPEC_CHARACTERS

please reward points if dis helps

Read only

Former Member
0 Likes
983

declare a constant that has all the special characters like

gc_spl(20) type c value '!@#$%....'

if string CA gc_spl.

string+0(sy-fdpos) = space.

endif.

or use

CHECK_STRING_SPEC_CHARACTERS

Read only

Former Member
0 Likes
984

data: str(100) type c.

data: str_n type string.

data: str_c type string.

data: len type i.

data: ofst type i.

str = '#ABCD%'.

len = strlen( str ).

do.

if ofst = len.

exit.

endif.

if str+ofst(1) co sy-abcde.

concatenate str_c str+ofst(1) into str_c.

else.

concatenate str_n str+ofst(1) into str_n.

endif.

ofst = ofst + 1.

enddo.

write:/ str.

write:/ str_c.

write:/ 'spacial chracter',20 str_n.

Function module <b>SF_SPECIALCHAR_DELETE</b> <b>DX_SEARCH_STRING</b>

l_address1 = i_adrc-street.

CHECK NOT L_ADDRESS1 IS INITIAL.

len = STRLEN( l_address1 ).

do len times.

if not l_address1+l(1) ca

'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 '.

  • if i_adrc-street+l(1) CO sy-abcde.

  • elseif i_adrc-street+l(1) CO L_NUMCHAR.

exit.

endif.

l = l + 1.

enddo.

data : spchar(40) type c value '~!@#$$%^&()?...'etc.

data :gv_char .

data:inp(20) type c.

take the string length .

len = strlen (i/p).

do len times

MOVE FNAME+T(1) TO GV_CHAR.

IF gv_char CA spchar.

MOVE fnameT(1) TO inp2T(1).

ENDIF.

T = T + 1.

enddo.

REPORT ZEX4 .

PARAMETERS: fname LIKE rlgrap-filename .

DATA: len TYPE i,

T TYPE I VALUE 0,

inp(20) TYPE C,

inp1(20) type c,

inp2(20) type c,

inp3(20) type c.

DATA :gv_char.

data : spchar(20) type c value '#$%^&*()_+`~'.

START-OF-SELECTION.

CONDENSE fname.

len = strlen( fname ).

  • WRITE:/ len.

DO len TIMES.

MOVE FNAME+T(1) TO GV_CHAR.

IF gv_char ca spchar.

MOVE fnameT(1) TO inpT(1).

ENDIF.

T = T + 1.

ENDDO.

CONDENSE INP.

write:/ 'Special Characters :', inp.

Rewards if useful..........

Minal

Read only

former_member188827
Active Contributor
0 Likes
983

data zstring type string value 'hi* how r u'.

data zerror type T130F-KZREF.

data zch.

CALL FUNCTION 'CHECK_STRING_SPEC_CHARACTERS'

EXPORTING

string = zstring

IMPORTING

CHARACTER = zch

ERRORFLAG = zerror

.

WRITE: / zch,zerror.

Read only

Former Member
0 Likes
983

hi

good

check this example

Write a program to give input as “+91-44-42040260”, output should be “ 91 44 42040260”.

Ans :

DATA:INPUT(15) VALUE '+91-44-42040260',

STR(4) VALUE '+ - '.

TRANSLATE INPUT USING STR.

WRITE:/ INPUT.

reward point if helpful.

thanks

mrutyun^

Read only

Former Member
0 Likes
983

Hi guys,

Thanks a million!!!

Best regards,

Karen