Posted 01 September 2012 - 01:27 PM
ComputerCraft Version Information: 1.3 Client / 1.3 Server
Description of Bug:
If you call stirng.find on a string that has been returned by string.sub, instead of the index of the match in the newly created substring, you get the index in the original string.
I came across this problem when trying to substring command line arguments, I assume these are partitioned by substring of the full shell string as string.find returns the position in the shell string instead of the argument.
Steps to Reproduce Bug:
Returns 11 instead of the expected 7
Workaround:
Concatenate a blank string to cause memory re-allocation
Description of Bug:
If you call stirng.find on a string that has been returned by string.sub, instead of the index of the match in the newly created substring, you get the index in the original string.
I came across this problem when trying to substring command line arguments, I assume these are partitioned by substring of the full shell string as string.find returns the position in the shell string instead of the argument.
Steps to Reproduce Bug:
local testString = "This is a sample string";
local testSubString = string.sub(testString,5);
local indexOfSample = string.find(testSubString,"sample");
print(indexOfSample);
Returns 11 instead of the expected 7
Workaround:
Concatenate a blank string to cause memory re-allocation
local testString = "This is a sample string";
local testSubString = string.sub(testString,5);
local indexOfSample = string.find(testSubString.."","sample");
print(indexOfSample);