Hi,
I am working on shortening a string to get a person's name. Essentially, the loop works through each character, expanding with each iteration until a target character is reached. The following is my attempt:
for i=1,1000 do
local a= string.sub("Emily: My foot hurts.",1,i)
if i==":" then
print(a)
break
end
end
As you can see, I tried to make the loop as big as possible, depending on how long sentences are because I would add a break to end the loop if the target character is reached (in this case, I want it to stop when there is a colon mark). The 1 should start at the first character of the string, and loop through until it finds the ":". Finally, it would print out the final string, in this case, "Emily".
In theory, this is how the loop would go: E Em Emi Emil Emily [stop] a= "Emily" (intended solution)
I appreciate any help in this matter.
Best,
Houlardy

2 comments
I'll answer this tomorrow if nobody gets to it. Don't have time to whip up an entire solution. You'll be using string.gmatch
good suggestion, thanks