如何将字符转换为字表 [英] How do I convert chars into a word table

查看:129
本文介绍了如何将字符转换为字表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个函数将字符串拆分为一个表,但是使用字符。

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



然后我有一个函数将char表变成一个word表。


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



除了,如果你有超过3,它只会返回三个字。

我不知道我做错了什么。



我尝试过:



从头开始重写函数。

尝试不同将字符串转换为字符的方法。

我已经确定问题出在Ta中bleToWords函数。


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.

推荐答案

我不用Lua编程。然而,当我遇到困难时,谷歌搜索是我第一次去,因为我知道我并不是唯一遇到过我遇到的问题的人。快速搜索每次都证明了这一点。



因此,互联网可以成为强大的帮助工具,也是您最好的朋友和导师。此搜索链接为您提供了大量解决方案: Lua获取字词 [ ^ ]
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[^]


这篇关于如何将字符转换为字表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆