| 04-22-2008, 12:58 AM | #1 |
I'm making a function that returns a section of a string. The section are divided by divider. The function will count to the target section and return that section only. The function works just fine, but i was wondering if it can be made more efficient? Here is the code: JASS:function StringReader takes string source, string divider, integer targetCount returns string local integer length = StringLength(source) local integer end = length local integer start = 0 local integer dividerCount = 0 local integer counter = 0 loop exitwhen counter == length if SubString( source, counter, counter + 1) == divider then set dividerCount = dividerCount + 1 if dividerCount == targetCount then set end = counter exitwhen true else set start = counter + 1 endif endif set counter = counter + 1 endloop return SubString( source, start, end) endfunction Here is an example of how it works: JASS:string a = "apple,peach,banana,others" string b = StringReader( a, ",", 3) b = banana |
| 04-22-2008, 01:36 AM | #2 |
I can't see any way to make it more efficient, no. |
