- 3
- 0
- 约3.19千字
- 约 4页
- 2018-04-17 发布于河南
- 举报
/bidepan2023/blog/item/5f49bda4468e91f09052eedc.html
LUA string库详解
2009-01-09 18:33string.byte (s [, i])
Returns the internal numerical code of the i-th character of s, or nil if the index is out of range. If i is absent, then it is assumed to be?1. i may be negative.
Note that numerical codes are not necessarily portable across platforms.
string.char (i1, i2, ...)
Receives 0 or more integers. Returns a string with length equal to the number of arguments, in which each character has the internal numerical code equal to its correspondent argument.
Note that numerical codes are not necessarily portable across platforms.
1. string库中所有的字符索引从前往后是1,2,...;从后往前是-1,-2,...2. string库中所有的function都不会直接操作字符串,而是返回一个结果s = [abc]string.len(s)??????? ==返回5string.rep(abc, 2) ==返回abcabcstring.lower(ABC) ==返回abcstring.upper(abc) ==返回ABCstring.sub(s, 2)???? ==返回abc]string.sub(s, -2)??? ==返回c]string.sub(s, 2, -2) ==返回abcstring.format(fmt, ...)返回一个类似printf的格式化字符串string.find(s, pattern, pos)第1个参数:源字符串第2个参数:待搜索之模式串第3个参数:A hint, 从pos位置开始搜索找到匹配返回:匹配串开始和结束的位置,否则返回nil简单的模式串s = hello worldi, j = string.find(s, hello)print(i, j) -- 1 5print(string.sub(s, i, j)) -- helloprint(string.find(s, world)) -- 7 11i, j = string.find(s, l)print(i, j) -- 3 3print(string.find(s, lll)) -- nil格式化的模式串s = Deadline is 30/05/1999, firmdate = %d%d/%d%d/%d%d%d%dprint(string.sub(s, string.find(s, date))) -- 30/05/1999下面的表列出了Lua支持的所有字符类:. 任意字符%s 空白符%p 标点字符%c 控制字符%d 数字%x 十六进制数字%z 代表0的字符%a 字母%l 小写字母%u 大写字母%w 字母和数字上面字符类的大写形式表示小写所代表的集合的补集。例如,%A非字母的字符:模式串中的特殊字符( ) . % + - * ? [ ^ $% 用作特殊字符的转义字符%. 匹配点;%% 匹配字符 %。转义字符 %不仅可以用来转义特殊字符,还可以用于所有的非字母的字符。当对一个字符有疑问的时候,为安全起见请使用转义字符转义他。用[]创建字符集[%w_] 匹配字母数字和下划线[01] 匹配二进制数字[%[%]]匹配一对方括号在[]中使用连字符-%d??? 表示 [0-9];%x??? 表示 [0-9a-fA-F][0-7] 表示 在[]开始处使用 ^ 表示其补集:[^0-7] 匹配任何不是八进制数字的字符;[^\n] 匹配任何非换行符户的字符。[^%s] == %S模式修饰符+ 匹配前一字符1次或多次* 匹配前一字符0次或多次;最长匹配- 匹配前一字符0次或多次;最短匹配? 匹配前一字符0次或1次^ 匹配字符串开头 $ 匹配字符串结尾捕获:用
您可能关注的文档
- 防腐防水方案.docx
- 基于偏振光检测的转速计.doc
- PTT卓越展示培训训前会.ppt
- 大傻瓜我走了.doc
- 合成革离型纸型号.doc
- 正截面第8,13,第14题答案.docx
- 耐高温涂料的简单介绍及在工业设备上应用分析.doc
- 关于蓝耳病的一些思考.doc
- 香港当代电影研究.doc
- 清明公祭轩辕黄帝文.doc
- 2025年新外研版三年级上册英语同步教学课件.pptx
- 红十字会大讲堂管理制度.docx
- 技术奇点(Singularity)理论的科学基础、哲学思辨与未来社会构想 _2026年1月.docx
- 公共艺术项目在激活城市消极空间(如高架桥下、废弃铁轨)中的作用 _2026年1月.docx
- “双减”政策对校外培训行业转型及家庭教育投入变化的影响 _2026年1月.docx
- Z世代员工对职场“摸鱼文化”的态度成因与管理对策研究 _2026年1月.docx
- 跨文化团队管理中的沟通障碍、文化冲突与融合策略案例分析 _2026年1月.docx
- 共享经济平台将劳动者归类为“合作伙伴”的伦理与法律责任 _2026年1月.docx
- 大型国际展会(如进博会、CES)的绿色会展实践与可持续发展评估 _2026年1月.docx
- 地理标识产品(如阳澄湖大闸蟹)与产地旅游的融合发展研究 _2026年1月.docx
原创力文档

文档评论(0)