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

Delete all non-numc from string

Former Member
0 Likes
13,082

Guys,

I want to remove all non-numeric characters from my string. Basically only want it to contain numbers before I pass it on.

Suggestion?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
5,132

Hi!

DATA: lv_int TYPE i, lv_len TYPE i.

lv_len = strlen(mystring).

CLEAR lv_int.

WHILE lv_int < lv_len.

IF NOT mystring+lv_int(1) CA '0123456789'.

MOVE space TO mystring+lv_int(1).

ENDIF.

ADD 1 TO lv_int.

ENDWHILE.

CONDENSE mystring NO-GAPS.

Regards

Tamá

Guys,

I want to remove all non-numeric characters from my string. Basically only want it to contain numbers before I pass it on.

Suggestion?

5 REPLIES 5
Read only

Former Member
0 Likes
5,133

Hi!

DATA: lv_int TYPE i, lv_len TYPE i.

lv_len = strlen(mystring).

CLEAR lv_int.

WHILE lv_int < lv_len.

IF NOT mystring+lv_int(1) CA '0123456789'.

MOVE space TO mystring+lv_int(1).

ENDIF.

ADD 1 TO lv_int.

ENDWHILE.

CONDENSE mystring NO-GAPS.

Regards

Tamá

Read only

0 Likes
5,132

Nice nice!

Read only

5,132

REPLACE ALL OCCURRENCES OF REGEX '[^[:digit:] ]'

IN l_variable WITH space.

SHIFT l_variable LEFT DELETING LEADING space.

Read only

5,132

Hi,


REPLACE ALL OCCURRENCES OF REGEX '[0-9]' IN l_var WITH ''.

any shorter and/or more efficient code?

Regards,

Clemens

Read only

Former Member
0 Likes
5,132

parameters: ch(10) type c.

data: ch1(1) type c.

data: ty type DD01V-DATATYPE.

data: l type i.

DATA: K TYPE I.

l = strlen( ch ).

k = 0.

while k < l.

ch1 = ch+k(1).

CALL FUNCTION 'NUMERIC_CHECK'

EXPORTING

STRING_IN = ch1

IMPORTING

STRING_OUT = ch1

HTYPE = ty.

if ty NE 'NUMC'.

ch+k(1) = '#'.

endif.

k = k + 1.

endWHILE.

REPLACE ALL OCCURRENCES OF '#' in CH with ''.

WRITE: CH.