Usage of negative values in text related functions in Feature Requests
|
|
Resolved
|
The copytext(), findtext(), and findtextEx() procs now accept negative values for indexes. 0 still means the end of the string, but -1 is the last character, -2 is next-to-last, and so on. For example, copytext(msg,-4) is equivalent to copytext(msg,length(msg)-3). In addition, these procs are less prone to crash with "out of bounds" errors if given bad input. copytext(msg,3,2) for instance now returns a blank string instead of crashing. This behavior only affects worlds compiled in the new version.
|
|
|
| Status: |
Resolved (495)
This issue has been resolved.
|
|
|
Currently, if you use a negative value in functions such as:
findtext(Haystack,Needle,Start=1,End=0) findtextEx(Haystack,Needle,Start=1,End=0) copytext(T,Start=1,End=0)
|
you will get a runtime error about index out of bounds or something. However, wouldn't it make sense that if the value '0' is the position of the last character of any string...that a value such as -1, could be the position right before the last character?
It'd save a lot of effort in parsing things, I think, instead of having to length() things to get the position of where something ends, especially if you know you only need the last x amt of characters from the string.
var/x = "dantom is cool" copytext(x,-4,0) copytext(x,length("dantom is")+2,0) copytext(x,length(x)-3,0)
|
|