string.sub?

Home Forums General Programming string.sub?

This topic contains 1 reply, has 1 voice, and was last updated by  human fly 3 months, 2 weeks ago.

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

    human fly
    Participant
    • Topics: 121
    • Replies: 1023
    • Total: 1144
    • ★★★★

    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: 121
    • Replies: 1023
    • Total: 1144
    • ★★★★

    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.

There is currently 1 user and 8 guests online
vernonr
Forum Statistics
Threads: 2,120, Posts: 14,909, Members: 8,764
Most users ever online was 5 on March 28, 2018 6:11 pm
Do NOT follow this link or you will be banned from the site!