Could I use "string.find" for this?
Thank you :)
Could I use "string.find" for this?
Thank you :)
You can detect how much character is in the string by using string.len(). Not to be confused, let me make an example and how is the concept:
Like a string called "LOL" have 3 character, we can use string.len("LOL") and... It returns three! But what is the last letter at? It's at the 3rd column. Well it matches with the length! Also, we can use string.sub() to get a specific place from the start to the end. Well, you wanted to locate the part only at the last letter. So what are we gonna do is:
local String = "I like apples"
local String2 = "I like banana"
print(string.sub(String, string.len(String), string.len(String))) -- s
print(string.sub(String2, string.len(String2), string.len(String2))) -- a
-- Not to be confused, string with capital s is the variable, and string with a small letter s is a built-in function
If you understand what I mean in the top and understood how it works, you can skip this. And mark this as an answer if this helped.
Also if you are confused, let me explain again, like "LOL" have 3 characters, the end is between the 3rd and the 3rd, that's how we locate one string letter. and string.len() returns the string length and "LOL" have 3 character and the 3 is also the last letter (in column) of the string.
What the system sees are the string.sub() of the string, as known as "LOL", get the letter between 3rd to 3rd, and the 3 comes from length.
Also if you want to make it lowercase or uppercase, use string.lower(String) or string.upper(String)
Thank you for reading! Bye bye
Also if you see peoples doing string.sub(String, 5), it means getting the string from 5 to the last letter or etc. But I'd recommend you that way so you can change it to any specific subs places.
Ohhhh, thank you
Probably, but you can also use string.sub()
e.g.
local str = "Bruhlol MAIN"
print(string.sub(str, 9)
which returns MAIN
Just a minor you can also do string.sub(str,#str)
Thank you!
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
if string.find("Some Strings", "s$"); Where the dollar sign means that the match must be at the end