lua string 库
| 函数 | 描述 | 示例 | 结果 |
| len | 计算字符串长度 | string.len("abcd") | 4 |
| rep | 返回字符串s的n个拷贝 | string.rep("abcd",2) | abcdabcd |
| lower | 返回字符串全部字母大写 | string.lower("AbcD") | abcd |
| upper | 返回字符串全部字母小写 | string.upper("AbcD") | ABCD |
| format | 返回一个类似printf的格式化字符串 | string.format("the value is:%d",4) | the value is:4 |
| sub | returns substring from index i to j of s | string.sub("abcd",2) | bcd |
| string.sub("abcd",-2) | cd | ||
| string.sub("abcd",2,-2) | bc | ||
| string.sub("abcd",2,3) | bc | ||
| find | 在字符串中查找 | string.find("cdcdcdcd","ab") | nil |
| string.find("cdcdcdcd","cd") | 1 2 | ||
| string.find("cdcdcdcd","cd",7) | 7 8 | ||
| gsub | 在字符串中替换 | string.gsub("abcdabcd","a","z"); | zbcdzbcd 2 |
| string.gsub("aaaa","a","z",3); | zzza 3 | ||
| byte | 返回字符的整数形式 | string.byte("ABCD",4) | 68 |
| char | 将整型数字转成字符并连接 | string.char(97,98,99,100) | abcd |
--------------------------------------------------------------------------------------------------
| 字符类 | 描述 | 示例 | 结果 |
| . | 任意字符 | string.find("",".") | nil |
| %s | 空白符 | string.find("ab cd","%s%s") | 3 4 |
| %S | 非空白符 | string.find("ab cd","%S%S") | 1 2 |
| %p | 标点字符 | string.find("ab,.cd","%p%p") | 3 4 |
| %P | 非标点字符 | string.find("ab,.cd","%P%P") | 1 2 |
| %c | 控制字符 | string.find("abcd\t\n","%c%c") | 5 6 |
| %C | 非控制字符 | string.find("\t\nabcd","%C%C") | 3 4 |
| %d | 数字 | string.find("abcd12","%d%d") | 5 6 |
| %D | 非数字 | string.find("12abcd","%D%D") | 3 4 |
| %x | 十六进制数字 | string.find("efgh","%x%x") | 1 2 |
| %X | 非十六进制数字 | string.find("efgh","%X%X") | 3 4 |
| %a | 字母 | string.find("AB12","%a%a") | 1 2 |
| %A | 非字母 | string.find("AB12","%A%A") | 3 4 |
| %l | 小写字母 | string.find("ABab","%l%l") | 3 4 |
| %L | 大写字母 | string.find("ABab","%L%L") | 1 2 |
| %u | 大写字母 | string.find("ABab","%u%u") | 1 2 |
| %U | 非大写字母 | string.find("ABab","%U%U") | 3 4 |
| %w | 字母和数字 | string.find("a1()","%w%w") | 1 2 |
| %W | 非字母非数字 | string.find("a1()","%W%W") | 3 4 |
| 字符类 | 描述 | 示例 | 结果 |
| % | 转义字符 | string.find("abc%..","%%") | 4 4 |
| string.find("abc..d","%.%.") | 4 5 |
| 字符类 | 描述 | 示例 | 结果 |
| [01] | 匹配二进制数 | string.find("32123","[01]") | 3 3 |
| [AB][CD] | 匹配AC、AD、BC、BD | string.find("ABCDEF","[AB][CD]") | 2 3 |
| [[]] | 匹配一对方括号[] | string.find("ABC[]D","[[]]") | 4 5 |
| [1-3] | 匹配数字1-3 | string.find("312","[1-3][1-3][1-3]") | 1 3 |
| [b-d] | 匹配字母b-d | string.find("dbc","[b-d][b-d][b-d]") | 1 3 |
| [^%s] | 匹配任意非空字符 | string.find(" a ","[^%s]") | 3 3 |
| [^%d] | 匹配任意非数字字符 | string.find("123a","[^%d]") | 4 4 |
| [^%a] | 匹配任意非字母字符 | string.find("abc1","[^%a]") | 4 4 |
| 字符类 | 描述 | 示例 | 结果 |
| () | 捕获字符串 | string.find("12ab","(%a%a)") | 3 4 ab |
| string.find("ab12","(%d%d)") | 3 4 12 |
| 修饰符 | 描述 | 示例 | 结果 |
| + | 表示1个或多个,匹配最多个 | string.find("aaabbb","(a+b)") | 1 4 aaab |
| string.find("cccbbb","(a+b)") | nil | ||
| - | 表示0个或多个,匹配最少个 | string.find("zzxyyy","(xy-)") | 3 3 x |
| string.find("zzzyyy","(x-y)") | 4 4 y | ||
| * | 表示0个或多个,匹配最多个 | string.find("mmmnnn","(m*n)") | 1 4 mmmb |
| string.find("lllnnn","(m*n)") | 4 4 n | ||
| ? | 表示0个或1个 | string.find("aaabbb","(a?b)") | 3 4 ab |
| string.find("cccbbb","(a?b)") | 4 4 b |
lua string 库的更多相关文章
- Lua string库整理
string库提供了字符串处理的通用函数. 例如字符串查找.子串.模式匹配等. 当在 Lua 中对字符串做索引时,第一个字符从 1 开始计算(而不是 C 里的 0 ). 索引可以是负数,它指从字符串末 ...
- Lua string库详解
1. string库中所有的字符索引从前往后是1,2,...;从后往前是-1,-2,...2. string库中所有的function都不会直接操作字符串,而是返回一个结果 string.byte(s ...
- lua string库
--lua中字符串索引从前往后是1,2,……,从后往前是-1,-2……. --string库中所有的function都不会直接操作字符串,只返回一个结果. -------------------- ...
- lua的string库与强大的模式匹配
lua原生解释器对字符串的处理能力是十分有限的,强大的字符串操作能力来自于string库.lua的string函数导出在string module中.在lua5.1,同一时候也作为string类型的成 ...
- Lua的string和string库总结
Lua有7种数据类型,分别是nil.boolean.number.string.table.function.userdata.这里我总结一下Lua的string类型和string库,复习一下,以便加 ...
- Lua 之string库
标准string库 基础字符串函数 string.len(s) 返回一个字符串的长度,例如 string.rep(s, n) 返回一个新的字符串,该字符串是参数s重复n次得到的结果,例如 )) -- ...
- 在lua的string库和正则表达式
一.前提要了解一下lua 的string几个方法 1. string库中所有的字符索引从前往后是1,2,...;从后往前是-1,-2,... 2. string库中所有的function都不会直接操作 ...
- Lua 中的string库(字符串函数库)总结
(字符串函数库)总结 投稿:junjie 字体:[增加 减小] 类型:转载 时间:2014-11-20我要评论 这篇文章主要介绍了Lua中的string库(字符串函数库)总结,本文讲解了string库 ...
- lua字符串处理(string库用法)
原文地址http://www.freecls.com/a/2712/f lua的string库是用来处理字符串的,基础函数如下 string.byte(s [, i [, j]]) string.by ...
随机推荐
- python set type 集合类型的数据介绍 (set frozenset)
python支持数学中的集合概念,如:通过in,not in 可以检查某元素是否在,不在集合中. python有两种集合类型,set(可以变的,不能哈希,不能用作字典的key),frozenset ...
- Layout Resource官方教程(4)<include>与<merge>
Re-using Layouts with <include/> THIS LESSON TEACHES YOU TO Create a Re-usable Layout Use the ...
- DOCTYPE, HTML和XHTML, Strict DTD和Transitional DTD, Quirks Mode和Standard Mode
在HTML里面声明DOCTYPE一般会有以下几种: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ...
- vsphere client cd/dvd 驱动器1 正在连接
esxi 5.1选择了客户端设备,打开控制台后,CD/DVD一直显示“CD/DVD驱动器1 正在连接” 解决方法:vSphere Client客户端问题,关闭和重新打开vSphere Client客户 ...
- poj 3295 Tautology (构造)
题目:http://poj.org/problem?id=3295 题意:p,q,r,s,t,是五个二进制数. K,A,N,C,E,是五个运算符. K:&& A:||N:! C:(!w ...
- 结构体buf_block_t
/** Buffer block for which an uncompressed page exists */ typedef struct buf_block_struct buf_block_ ...
- Hibernate4.x之映射关系--双向1-n
双向1-n与双向n-1是完全相同的两种情形 双向1-n需要在1的一端可以访问n的一端,反之亦然. 域模型:从Order到Customer的多对一双向关联需要在Order类中定义一个Customer属性 ...
- MySQL查询大小写是否敏感问题分析
mysql数据库在做查询时候,有时候是英文字母大小写敏感的,有时候又不是的,主要是由mysql的字符校验规则的设置决定的,通常默认是不支持的大小写字母敏感的. 1. 什么是字符集和校验规则? 字符集 ...
- Hadoop2.7.2安装笔记
1.设置免密SSH登录 $ ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa $ cat ~/.ssh/id_dsa.pub >> ~/.ssh/autho ...
- 劳动节BT5 aircrack-ng战记
劳动节最后一天没事,想捣鼓一下BT5破解无线wep/wpa,BT5+virtual box早已准备就绪,上网专门找了一些资料,并买了一个据评测很兼容的usb网卡tp-link wn722n,芯片代号A ...