Skip to Content
author's profile photo Former Member
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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • author's profile photo Former Member
    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

    Add a comment
    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.

  • author's profile photo Former Member
    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!

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.