Former Member

# Determining the length of characters before space

How can I use the search functionality to determine the length of the first word before the space?

For example lets suppose the string is 'Uzbekistan Russia USA' how can I use the search or any other functionality to determine the length of Uzbekistan? I cannot use a constant number and I have to dynamically calculate for each string.

With best regards,

Ketan

10|10000 characters needed characters exceeded

### Related questions

• Former Member
Posted on Jul 10, 2007 at 07:45 AM

data : text(40) value 'Uzbekistan Russia USA' ,

text1(40),

text2(40),

len type i.

split text at space into text1 text2.

compute len = strlen( text1 ).

write : / len.

regards

shiba dutta

10|10000 characters needed characters exceeded
• Former Member

since the number od words are not defined hence u need to split data and take it into a internal table.

data: itab type table of string.

split text at space into itab.

loop at itab.

compute len = strlen( itab ).

write : / len.

endloop.

• Former Member
Posted on Jul 10, 2007 at 07:46 AM

Hi,

DATA: str1 TYPE string,

str2 TYPE string,

str3 TYPE string,

itab TYPE TABLE OF string,

text TYPE string.

text = `What a drag it is getting old`.

SPLIT text AT space INTO: str1 str2 str3,

TABLE itab.

describe str1 length len.

Reward if useful!

10|10000 characters needed characters exceeded
• Former Member
Posted on Jul 10, 2007 at 07:54 AM

Hi Ketan,

try this:

data : text(40) value 'Uzbekistan Russia USA'.

data: begin of itab occurs 0,

txt(40),

end of itab.

*

data: strlen type i.

split text at space into table itab.

*

loop at itab.

strlen = strlen( itab-txt ).

write: / itab-txt, strlen.

endloop.

Regards, Dieter