Split Function Problem

Home Forums Problems and solutions in GDL Object design Split Function Problem

This topic contains 1 reply, has 2 voices, and was last updated by  Barry Kelly 2 years, 3 months ago.

  • Author
  • #3982

    James Goode


    I am trying to use the split function on parameter obtained from a home story request function.
    What I want to achieve is to show just the GF instead of GF-Ground Floor.

    x = REQUEST ("Home_story", "", index, story_name)
    n = SPLIT (story_name, "%s-%s %s", num) 
    IF n THEN
        text2 0, 0, num

    This is what I have so far. It removes the “Floor” part of the code but I don’t know how to get it to remove the “-Ground” part of the output

    Any help would be appreciated,

  • #3985

    Barry Kelly

    If your storey name is “GF-Ground Floor” then you will find that “GF-Ground” is one part of the string and “Floor” is another.
    So …

    x = REQUEST (“Home_story”, “”, index, story_name)

    n = SPLIT (story_name, "%s %s", split1, split2) 
    IF n THEN
        text2 0, 0.5, story_name
        text2 0, 0, split1
        text2 0, -0.5, split2

    What you actually need to do is search for the “-” character.
    Assuming this is the same for all your storeys.
    Then output the required number of characters.

    pos = STRSTR (story_name, "-")
    !    text2 0, 0, pos
    prefix = STRSUB (story_name, 1, pos-1)
        text2 0, -2, prefix

    Of course if the prefix is always 2 characters you know this already so you can just output the first 2 characters with STRSUB.

    Versions 6.5 to 22
    Dell XPS- i7-6700 @ 3.4Ghz, 16GB ram, GeForce GTX 960 (2GB), Windows 10
    Dell Precision M6800 - i7 4700MQ @ 2.40GHz, 16GB RAM, AMD FirePro M6100 (2GB), Windows 7 64bit

You must be logged in to reply to this topic.