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

Reg : Extracting particular word from string

Former Member
0 Likes
2,131

Dear Experts,

I need to extract a particular word from my string,

Ex : O/10/01/025 / DEMO CAR

I want to extract the word DEMO..How to do that..?

Dear Experts,

I need to extract a particular word from my string,

Ex : O/10/01/025 / DEMO CAR

I want to extract the word DEMO..How to do that..?

5 REPLIES 5
Read only

former_member206377
Active Contributor
0 Likes
1,274

DATA: lv_string TYPE string value 'O/10/01/025 / DEMO CAR'  , 
      lv_string2  TYPE string value 'DEMO' . 

IF  lv_string CS  lv_string2. 
  ... 

ENDIF. 
Read only

Former Member
0 Likes
1,274

Hi,

1.First Find the the Position using the SEARCh command.You will get SY-FDPOS value.

2.You length of the string.

3.Access the field like field1+sy-fdpos(lengthofword).

Thanks & Regards,

Vamsi.

Read only

alex_cook
Active Participant
0 Likes
1,274

Hi,

Also it depends on what you want to do with it. If you want to remove the word completely you could try:

REPLACE FIRST OCCURRENCE OF 'DEMO' with ''.

Or if you want the offset value (the position of the substring) you can use:

DATA: l_offset type i.

FIND FIRST OCCURRENCE OF 'DEMO' MATCH OFFSET l_offset.

Cheers

Alex

Edited by: Alex Cook on Feb 3, 2010 6:31 AM

Read only

Former Member
0 Likes
1,274

arthi,

please explain your exact need. you know the word or position or want to search a word or a particukar length of word or you want to find the word in the string??

Read only

Former Member
0 Likes
1,274

Hi,

please check below statments.

DATA: text TYPE STRING. 

text = 'Everyone knows this'. 

FIND 'know' IN text.

even you can use SEARCH statment.

DATA F(20) VALUE 'Peter Paul Mary'. 

SEARCH F FOR '*UL' AND MARK.

SY-SUBRC is now set to 0, since the search string was found in 'Paul'. SY-FDPOS has the value 6, since the character string found starts at the offset 6. Also, the search string is marked, so that the new contents of F are as follows:

'Peter PAUL Mary'

Thanks,