Click here to Skip to main content
15,890,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a function that splits a string up into a table, but with chars.
function strToTable(stringer)
	local newTable = {}
        for i = 1, #stringer do
    	newTable[i] = stringer:sub(i, i)
	end
	return newTable
end

and then I have a function that turns the char table into a word table.
function tableToWords(t)
	local newT = {}
	local Word = ""
	for _,Char in pairs(t) do
		if (Char == " ") then
			table.insert(newT, Word)
			Word = ""
		else
			Word = Word .. Char
		end
	end
	return newT
end

Except, it only returns three words if you have more than 3.
I have no Idea what I did wrong.

What I have tried:

Rewriting the Function from Scratch.
Tried different methods of converting the string to chars.
I have determined the problem is in the TableToWords function.
Posted
Updated 10-Sep-17 15:35pm

1 solution

I don't program in Lua. However when I get stuck, Google Search is my first go to as I know that I am not the only one who has encountered the problems that I experience. A quick search proves that every time.

So, the internet can be a powerful help tool, and your best friend and mentor, when used. This search link has tonnes of solutions for you: Lua get words[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900