I want to figure out how many words are in a string but to do this I would guess that I need to figure out how many ' ' I have within the text. I have tried things such as:
print(string.match("Hello, this is ryan and welcome to my test","e"))
However, all this has done is printed the letter 'e' as that is what the string contains. Is there anything such that I can replace the letter 'e' with the amount of blank spaces there are which will also figure out the amount of words there are or will I need more script to do this task?
Ok, lets try it!
First Step : We need to know what we are making, and how we are making it. So first of all we need a string. If we already make a string we can start with the coding part!
Second Step : Second, we need to know how to use the "#" in a for loop. So lets try it and lets check it out.
Third Step : Enjoy coding! Always have to enjoy what are you doing! Play some music while you script or even play a game before so you will be relaxed.
Lets get into the code!
local whitespace = 0 local stringM = ("I love you so much!") for i = 1, #stringM do if (string.sub(stringM, i, i) == " ") then whitespace = whitespace + 1 end end print(whitespace)
That how you know how many spaces are in a string! Is a easy piece of code and you don't need any knowledge of difficult functions.
I hope my answer already solve your question. If it like that, plese accept my answer! That will help me a lot.
Keep scripting!
Try checking articles about string https://developer.roblox.com/en-us/api-reference/lua-docs/string