Hello.
I am working on an interesting project at the moment yet I need SPLIT() to work correctly for digits and ignore character divisions that are not part of a set. Let me explain.
If you have:
a="12345678" b=split(a,"3") c=b[1] cls() ?c |
You get a nice "12" which is correct
If you try:
a="12345678" b=split(a,"") c=b[1] cls() ?c |
You get "1" which is interesting cause it means you can separate a string by individual characters this way.
But what about split() for something that is not there ?
HERE IS THE PROBLEM !
a="12345678" b=split(a,"z") c=b[1] cls() ?c |
You get this crazy # of 24910 !
Where the heck did that come from ? I can understand it doing the string but there is no "9" even in my pattern !
Comments ?
You want to pass false as the 3rd parameter to avoid automatic conversion of strings to numbers.
A 3rd statement, @thisismypassword ?
Oh for good grief. ==SIGH==
I didn't know there was a 3rd argument. Closing out this ticket. That was fast. :D Thanks !
I think I need to stop trying to learn code by reading others examples and set down to learn the commands properly from the real instructions and documents.
Still ... I think split() should not return anything if the character is not in there, or at least that would help me:
a="12345678" b=split(a,"z",false) c=b[1] cls() ?c |
Returns "12345678" instead of ""
Well I understand in your particular case an empty string as result would be useful and very welcome... 😉
But I suppose the entire -unsplitted- string is expected from a split function (simply, it failed to split it because there's no such separator, the full string as first and sole token is returned).
Hi @Heracleum:
It's OK, I just code around it:
function instr(a,b) local c=split(a,b,false)[1] if (#c>=#a or b=="") return 0 return #c+1 end |
[Please log in to post a comment]