2008 May 26 2:21 PM
Hi,
can i find a number in a string?
es.
String is xxxx16080xxxxx
Edited by: Alfonso Manzo on May 26, 2008 3:22 PM
2008 May 26 2:36 PM
DATA text TYPE string.
text = 'YTD<J KHGYGJNKLJKKN777GLHGKLB'.
SEARCH text FOR '777'.
IF sy-subrc = 0.
write:/ sy-fdpos.
ENDIF.
DATA text TYPE string.
text = 'YTD<J KHGYGJNKLJKKN777GLHGKLB'.
SEARCH text FOR '777'.
IF sy-subrc = 0.
write:/ sy-fdpos.
ENDIF.
2008 May 26 2:32 PM
Hello,
Yes, you can. Use the command FIND .
DATA: patt TYPE string VALUE `16080`,
off TYPE i,
mlen TYPE i.
FIND patt IN
`Everybody knows this is nowhere 16080`
MATCH OFFSET off
MATCH LENGTH mlen.
IF sy-subrc = 0.
WRITE / off.
off = off + mlen.
ENDIF.
Regards,
2008 May 26 2:36 PM
DATA text TYPE string.
text = 'YTD<J KHGYGJNKLJKKN777GLHGKLB'.
SEARCH text FOR '777'.
IF sy-subrc = 0.
write:/ sy-fdpos.
ENDIF.
2008 May 26 2:45 PM
I don't know the number.
I have a material description
xxxx919190xxxx and i find a number in description.
es.
xxxx98723xxx -> 98723
xxx 98656 xx -> 98656
256236 -> 256236
2008 May 26 2:44 PM
DATA text TYPE string.
text = 'YTD<J KHGYGJNKLJKKN777GLHGKLB'.
IF text CA '1234567890'. " contains any
WRITE:/ text.
ENDIF.
2008 May 26 2:49 PM
Hi,
try something like that:
REPORT test.
DATA:
x(132),
i TYPE i,
rc LIKE sy-subrc.
x = 'xxx1280987xxx'.
PERFORM match_integer USING x
CHANGING i
rc.
WRITE: / rc, i.
x = 'xxxxxxxxyyxx9'.
PERFORM match_integer USING x
CHANGING i
rc.
WRITE: / rc, i.
x = '1xx1280987xxx'.
PERFORM match_integer USING x
CHANGING i
rc.
WRITE: / rc, i.
x = 'ABCxxx&&## ff'.
PERFORM match_integer USING x
CHANGING i
rc.
WRITE: / rc, i.
&----
*& Form MATCH_INTEGER
&----
FORM match_integer USING x
CHANGING i
rc.
DATA:
len TYPE i,
off TYPE i.
i = 0.
rc = 1. "default error
len = STRLEN( x ).
IF len = 0.
EXIT.
ENDIF.
find start
WHILE off < len.
IF x+off(1) >= '0' AND
x+off(1) <= '9'.
EXIT.
ENDIF.
off = off + 1.
ENDWHILE.
IF off = len.
EXIT.
ENDIF.
read int
WHILE off < len.
i = i * 10 + x+off(1).
off = off + 1.
IF x+off(1) < '0' OR
x+off(1) > '9'.
EXIT.
ENDIF.
ENDWHILE.
IF x+off(1) >= '0' AND
x+off(1) <= '9'.
i = i * 10 + x+off(1).
ENDIF.
rc = 0.
ENDFORM. " MATCH_INTEGER
2008 May 26 2:59 PM
DATA text TYPE string.
data: num(20) type n.
text = 'YTD<JKHGYGJNKLJKKN777GLHGKLB'.
num = text.
write: num.
ouput = 777.
2008 May 26 11:39 PM
Hello Alfonso,
In addiction to previous replies, you can also use regular expressions for this.
Here's an example:
DATA: lv_string TYPE string VALUE 'My Name is 230434 Bruno'.
DATA: lv_pattern TYPE string VALUE '([0-9]+)'.
DATA: lv_result TYPE string.
FIND REGEX lv_pattern IN lv_string IGNORING CASE
SUBMATCHES lv_result.
In this case, lv_result variable will get the 230434 number from the string 'My Name is 230434 Bruno'.
Regards,
Bruno
2008 May 27 4:05 AM
Hi,
Test the below code :
data : len type i,
str type string,
str1 type string,
final_str type string,
pos type i.
data : h_type type DD01V-DATATYPE.
parameters : num(20) type c.
str = num.
len = strlen( str ).
pos = 0.
do len times.
str1 = str+pos(1).
CALL FUNCTION 'NUMERIC_CHECK'
EXPORTING
string_in = str1
IMPORTING
* STRING_OUT =
HTYPE = h_type.
if h_type = 'NUMC'.
concatenate final_str str1 into final_str.
ENDIF.
pos = pos + 1.
clear str1.
enddo.
write : final_str.If above works as per your requirement then reward me.
Regards,
Raghu
2008 May 27 5:36 AM
data:search(10) type c value '0123456789'.
data:string_val type string.
string_val = 'abdc16080efgghi'.
if string_val cp search.
write: 'Found'.
endif.
2008 May 27 5:42 AM
sorry its like this..
data:search(10) type c value '0123456789'.
data:string_val type string.
string_val = 'abdc16080efgghi'.
if string_val ca search.
write: 'Found'.
endif.
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |