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

How to find string with trailing space

sourabh_chugh
Advisor
Advisor
0 Likes
625

Hi,

I need to search a word instead of string from another string.

I tried below code and expected that FIND will not search 'weeds' but it seems FIND ignores trailing spaces of string zstr and thus finds word 'weeds'.

***********************************************************

DATA: zstr type string value 'we ',

lv_string type string value 'These are weeds',

result_tab TYPE match_result_tab.

FIND FIRST OCCURRENCE OF regex zstr IN lv_string

IGNORING CASE

RESULTS result_tab.

**********************************************************

Please consider that zstr is runtime variable with no fixed length.

If anybody has the solution, reply back fast !

Regards,

Sourabh

Hi,

I need to search a word instead of string from another string.

I tried below code and expected that FIND will not search 'weeds' but it seems FIND ignores trailing spaces of string zstr and thus finds word 'weeds'.

***********************************************************

DATA: zstr type string value 'we ',

lv_string type string value 'These are weeds',

result_tab TYPE match_result_tab.

FIND FIRST OCCURRENCE OF regex zstr IN lv_string

IGNORING CASE

RESULTS result_tab.

**********************************************************

Please consider that zstr is runtime variable with no fixed length.

If anybody has the solution, reply back fast !

Regards,

Sourabh

2 REPLIES 2
Read only

Former Member
0 Likes
584

hi,

Check out in this way ...


 if  lv_string cp zstr. 
   write : 'Success'.
 else.
  write : 'Failed'.
 endif.  

Read only

Former Member
0 Likes
584

Hi,

Hi,

DATA STRING(30) VALUE 'This is a little sentence.'.

WRITE: / 'Searched', 'SY-SUBRC', 'SY-FDPOS'.

ULINE /1(26).

SEARCH STRING FOR 'X'.

WRITE: / 'X', SY-SUBRC UNDER 'SY-SUBRC',

SY-FDPOS UNDER 'SY-FDPOS'

SEARCH STRING FOR 'itt '.

WRITE: / 'itt ', SY-SUBRC UNDER 'SY-SUBRC',

SY-FDPOS UNDER 'SY-FDPOS'

SEARCH STRING FOR '.e .'.

WRITE: / '.e .', SY-SUBRC UNDER 'SY-SUBRC',

SY-FDPOS UNDER 'SY-FDPOS'.

SEARCH STRING FOR '*e'.

WRITE: / '*e ', SY-SUBRC UNDER 'SY-SUBRC',

SY-FDPOS UNDER 'SY-FDPOS'.

SEARCH STRING FOR 's*'.

WRITE: / 's* ', SY-SUBRC UNDER 'SY-SUBRC',

SY-FDPOS UNDER 'SY-FDPOS'.

Hope it will solve your problem..

Pls. reward if useful...