- ToLua的Example示例学习笔记21_String
- ToLua的Example示例学习笔记_总集篇
- ToLua的Example示例学习笔记03_CallLuaFun
- ToLua的Example示例学习笔记13_CustomLoad
- ToLua的Example示例学习笔记22_UseList
- ToLua的Example示例学习笔记11_Delegate
- ToLua的Example示例学习笔记02_ScriptsFro
- ToLua的Example示例学习笔记05_LuaCorouti
- ToLua的Example示例学习笔记04_AccessingL
- ToLua的Example示例学习笔记09_Dictionary
这个例子演示了在lua中如何使用String。
「1」代码
操作代码如下:
function Test()
local str = System.String.New('男儿当自强')
local index = str:IndexOfAny('儿自')
print('and index is: '..index)
local buffer = str:ToCharArray()
print('str type is: '..type(str)..' buffer[0] is ' .. buffer[0])
local luastr = tolua.tolstring(buffer)
print('lua string is: '..luastr..' type is: '..type(luastr))
luastr = tolua.tolstring(str)
print('lua string is: '..luastr)
end
「2」需要了解的部分
- Lua代码中的比较好理解:str:IndexOfAny找第一个的位置,str:ToCharArray则将字符串转为字符数组。tolua.tolstring可将字符数组或字符串转为Lua的字符串,类型变了。





网友评论