I am wondering if you can substract specific letters from a string.
How do i substract spcific letters from a string ?
1 answer
Solution:
There is a workaround that would work. First, define two variables:
local currentString = "This is a string"
local subtractedString = "" --Subtracted string will be our result
Now, let's say I wanted to take out the "is" in our currentString variable. I could simply get the number positions of letters before the "is" in our string. Those would be 5 (space before "is") and 9 (the words after "is"). I would then write code along these lines:
subtractedString = string.sub(currentString,1,5) .. string.sub(currentString,9,#currentString)
currentString = subtractedString
print(subtractedString)
This would return the result of "This a string"
Explanation: string.sub requires three parameters. These are what string we are going to get letters from (we want to get letters from our currentString), what digit to start at (I started at positions 1 and 9), and what part to end at (5 and #currentString, the hashtag getting the length of the string). In this case, I got the first five digits which is "This ". Then, we skipped three digits ("is ") including the space because we didn't want an extra long space. Then, we simply got the rest of the string.
Note: If you want to subtract the end or beginning of a string, use only one string.sub()
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
And what would be if you dont know the length of the string and want to delete the last five letters? Sorry i am kinda stupid XD!