Split Function Problem

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

Viewing 1 reply thread
  • Author
    Posts
    • #3982
      James Goode
      Participant

      Hi,

      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
      ENDIF

      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,
      Thanks

    • #3985
      Barry Kelly
      Participant

      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
      ENDIF

      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

Viewing 1 reply thread
  • The forum ‘Object design’ is closed to new topics and replies.