Home Forums General Programming string.sub?

This topic contains 1 reply, has 1 voice, and was last updated by  human fly 1 week, 2 days ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #81876

    human fly
    Participant

    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

    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)

You must be logged in to reply to this topic.

Comments are closed.