string.sub?

Home Forums General Programming string.sub?

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #81876
    human fly
    Participant
      • Topics: 124
      • Replies: 1070
      • Total: 1194
      • ★★★★

      hi,
      i want to use string.sub to get the number at the end of
      a name (suffix). if i do:
      sub=tonumber(string.sub(sName,-1))
      it is ok for numbers 0-9, but i can’t get numbers/suffixes
      with more than one character – ie: i need 1-24, names are
      ‘pad1’ to ‘pad24’

      i tried numbering 01-24 but it hasn’t been working for some
      reason (although i think it did previously, going to try again).

      any workarounds for this?
      thanks.

      #81877
      human fly
      Participant
        • Topics: 124
        • Replies: 1070
        • Total: 1194
        • ★★★★

        aaaah… figured it out: i was counting from the end
        when i didn’t need to. as the names are ‘pad’..n, all
        i had to do was count from the beginning of the name,eh.
        so that’s:
        sub=tonumber(string.sub(sName,4))
        and no need to try to number 01,02,etc. as that cannot
        match for i=1,24
        duh, simple solutions.

      Viewing 2 posts - 1 through 2 (of 2 total)
      • The forum ‘Programming’ is closed to new topics and replies.
      There is currently 0 users and 109 guests online
      No users are currently active
      Forum Statistics
      Threads: 2,495, Posts: 17,374, Members: 77,605
      Most users ever online was 12 on January 22, 2019 3:47 pm
      Ctrlr