Is there a way to count the number of sentences or at least count the number of words, not just the number of letters in a TextBox?
Well, if you want to count words or sentences, you could take the contents of the text box and use string.split to separate the words. You can then use list.getn to find the number of words/sentences!
Hope this helps!
This should work.
local function CountWords(s: string): number
local _, n = s:gsub("%w+", "")
return n;
end
list.len isn’t a built-in property.
There are quite a few ways you can go about getting the word count/sentence count of a textbox’s text.
Words:
local textbox = script.Parent
textbox:GetPropertyChangedSignal("Text"):Connect(function()
print(#textbox.Text:split(" ").." number of words.")
end)
local textbox = script.Parent
textbox:GetPropertyChangedSignal("Text"):Connect(function()
local count = 0
for word in textbox.Text:gmatch("%w+") do
count += 1
end
print(count.." number of words.")
end)
Sentences:
local textbox = script.Parent
textbox:GetPropertyChangedSignal("Text"):Connect(function()
print(#textbox.Text:split(".").." number of sentences.")
end)
local textbox = script.Parent
textbox:GetPropertyChangedSignal("Text"):Connect(function()
local count = 0
for sentence in textbox.Text:gmatch("[^\.]+") do
count += 1
end
print(count.." number of sentences.")
end)
table.getn, my bad! (character limit)