Lua - 将字符串转换为表格 [英] Lua - convert string to table
本文介绍了Lua - 将字符串转换为表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将字符串文本转换为表格,并且此文本必须按字符进行划分.每个字符都必须在表的单独值中,例如:
I want to convert string text to table and this text must be divided on characters. Every character must be in separate value of table, for example:
- a="文本"
- --将字符串(a)转换为表(b)
- --显示表格(b)
- b={'t','e','x','t'}
推荐答案
你可以使用 string.gsub 函数
You could use string.gsub function
t={}
str="text"
str:gsub(".",function(c) table.insert(t,c) end)
这篇关于Lua - 将字符串转换为表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文