自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Lua標(biāo)準(zhǔn)庫(kù) - 字符串處理(string manipulation)

開(kāi)發(fā) 前端
字符串庫(kù)為L(zhǎng)ua提供簡(jiǎn)易的字符串處理操作,所有的字串操作都是以1為基數(shù)的(C以0),也可使用負(fù)向索引,最后一個(gè)索引為-1 ; 所有的函數(shù)都存放在string表,并且已建立元表。

字符串庫(kù)為L(zhǎng)ua提供簡(jiǎn)易的字符串處理操作,所有的字串操作都是以1為基數(shù)的(C以0),也可使用負(fù)向索引,最后一個(gè)索引為-1 ; 所有的函數(shù)都存放在string表,并且已建立元表(__index=string表)

所以string.byte(s,i) <=> s:byte(i)

1、string.byte(s [, i [, j]])

功能:返回從i到j(luò)的字符所對(duì)應(yīng)的數(shù)值(字符 到 ASCII值),i默認(rèn)為1,j默認(rèn)為i的值

如:s="123456" s:(1,2) => 49 50

--------------------------------------------------------------------------------

2、string.char (···)

功能:返回ASCII值參數(shù)對(duì)應(yīng)的字符串

如:string.char(49,50) => 12

--------------------------------------------------------------------------------

3、string.dump(function)

功能:返回指定函數(shù)的二進(jìn)制代碼(函數(shù)必須是一個(gè)Lua函數(shù),并且沒(méi)有上值)

--------------------------------------------------------------------------------

4、string.find(s, pattern [, init [, plain]])

功能:查找s中首次出現(xiàn)pattern的位置,如果找到則返回首次出現(xiàn)的起始和結(jié)束索引否則返回nil

init:為搜索位置的起始索引,默認(rèn)為1(也可以用負(fù)索引法表示)

plain:true 將關(guān)閉樣式簡(jiǎn)單匹配模式,變?yōu)闊o(wú)格式匹配

--------------------------------------------------------------------------------

5、string.format (formatstring, ···)

功能:格式化字符串formatstring參數(shù)與C差不多

其中:*, l, L, n, p, h不被支持

c, d, E, e, f, g, G, i, o, u, X, x:接受數(shù)字參數(shù)

q, s:接受字符串參數(shù)

%q:為自動(dòng)將對(duì)應(yīng)參數(shù)字串中的特殊字符加上\

如:string.format('%q', 'a string with "quotes" and \n new line')等于

"a string with \"quotes\" and \

new line"

注:此函數(shù)不能接受字符串中間帶\0的字符

--------------------------------------------------------------------------------

6、string.gmatch(s, pattern)

功能:返回一個(gè)迭代函數(shù),每次調(diào)用此函數(shù),將返回下一個(gè)查找到的樣式串對(duì)應(yīng)的字符

如: s = "hello world from Lua"

for w in string.gmatch(s, "%a+") do

print(w)

end

為 hello

word

from

Lua

字串到表的賦值

t = {}

s = "from=world, to=Lua"

for k, v in string.gmatch(s, "(%w+)=(%w+)") do

t[k] = v

end

--------------------------------------------------------------------------------

7、string.gsub (s, pattern, repl [, n])

功能:返回一個(gè)經(jīng)repl替換pattern的字符串及替換的次數(shù)

s:待替換的字串

pattern:查找的字串

repl:要替換的內(nèi)容(可以為字串,表,函數(shù))

當(dāng)repl為字符串時(shí):進(jìn)行對(duì)應(yīng)字串的替換,%0~%9 %0為全匹配 %% 為%

當(dāng)repl為表時(shí):

當(dāng)repl為函數(shù)時(shí):每次查找到字符都將

原文鏈接:

責(zé)任編輯:陳四芳 來(lái)源: 來(lái)自ITPUB論壇
相關(guān)推薦

2013-12-12 16:59:15

Lua表處理

2011-08-23 14:26:07

Lua字符串

2013-12-12 17:03:57

Lua腳本語(yǔ)言

2013-12-12 17:27:51

Lua協(xié)同

2010-11-26 09:51:54

MySQL字符串

2020-05-12 08:53:15

JavaScript字符串處理庫(kù)

2021-08-26 11:41:50

字符串String.jsVoca

2023-10-27 07:03:22

字符串String類(lèi)型

2010-06-04 14:59:06

MySQL數(shù)據(jù)庫(kù)

2010-08-04 11:23:15

Flex字符串

2010-07-14 16:35:52

Perl字符串處理函數(shù)

2013-12-03 17:28:56

Lua腳本語(yǔ)言

2024-12-05 10:29:13

Rust字符串類(lèi)型

2010-07-19 15:07:46

Perl字符串處理函數(shù)

2010-10-09 11:54:46

MySQL字符串

2013-12-12 17:21:46

Lua出入輸出

2024-03-05 18:29:54

JavaString字符串

2021-05-27 08:59:09

String字符串操作

2021-11-07 07:51:01

JavaString字符串

2009-11-26 16:26:32

PHP字符串mbstr
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)