1. #1
    Deleted

    strsplit problem ?

    Hi,

    I have a problem that I don't understand. I try to split a string into an array, here's what I'm expecting :

    Code:
    local myTable = strsplit("," , "A,B,C,D,E,F", 6)
    
    > should be returning
    myTable = {"A", "B", "C", "D", "E", "F"}
    I know strsplit isn't a native lua function but it is implemented by blizzard in WoW.
    And it works !

    When I type /dump strsplit("," , "A,B,C,D,E,F", 6) I get this :
    Code:
    [1]="A",
    [2]="B",
    [3]="C",
    [4]="D",
    [5]="E",
    [6]="F"
    ... so what's your problem you might be thinking.
    The problem is, when I try to use that code into my addon file, it returns "A". As a string.
    I'll show you the addon code part that works on that, can you tell me if you see a mistake leading to this ? Thanks.

    Code:
    local addChans = strupper(additionalChannelsEditBox:GetText()) -- here I have a string of the format "A, B, C, D, E, F"
       
    addChans = gsub(addChans, " ", "") -- now it's "A,B,C,D,E,F" without extra spaces
       
    addChans = strsplit(",", addChans, 6) -- should be {"A", "B", "C", "D", "E", "F"}, is "A"
    I have checked the first two lines by printing their result, they are working as intended. At first I thought the issue might come from the addChan variable becoming a table from a string (power of the lua !) but even by declaring a new local variable for the table it didn't work.

    Any advice ?

    Iphi.

    P.S. : sorry for bad English, if any too big mistakes please tell me I'll correct. Not my native language ^^

  2. #2
    strsplit() returns parameters, not a single table. If you want a table, try this:

    Code:
    addChans = {strsplit(",", addChans, 6)}

  3. #3
    Deleted
    It actually returns 6 return values instead of a table with 6 values:
    Code:
    local myTable={strsplit("," , "A,B,C,D,E,F", 6)}
    should do the trick.

  4. #4
    Deleted
    It did the trick. Thank you
    And sorry I didn't respond earlier, had no access to internet before now. Again, thanks !

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •