<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      lua 字符串處理

      匹配模式(pattern)

      • . 任何單個字符
      • %a 任何字母
      • %c 任何控制字符
      • %d 任何數字
      • %g 任何除空白符外的可打印字符
      • %l 所有小寫字母
      • %p 所有標點符號
      • %s 所有空白字符
      • %u 所有大寫字母
      • %w 所有字母及數字
      • %x 所有 16 進制數字符號
      • %x (這里 x 是任何非字母/數字的字符) 表示字符 x。如 %% 表示百分號%,%. 表示點號.,%/ 表示斜杠/。
      • [set] 表示 set 中所有字符的聯合,找到其中任一字符即表示匹配。可以用 - 連接,如[0-9] 表示 0 到 9 這十個數字。
      • [^set] 表示 set 的補集。

      字符類與特殊意義符號:

      • 單個字符類跟一個 '*',將匹配零個或多個該類字符,匹配盡可能的串。
      • 單個字符類跟一個 '-',將匹配零個或多個該類字符,匹配盡可能的串。
      • 單個字符類跟一個 '+',將匹配一個或多個該類字符,匹配盡可能的串。
      • 單個字符類跟一個 '?',將匹配零個或一個該類字符。
      • %n,這里 n 可以從 1 到 9,匹配捕獲的第 n 個子串。
      • %bxy,這里的 x 和 y 是兩個明確的字符,匹配以 x 開始 y 結束。如 %b() 匹配包括小括號在內括起來的字符串。
      • %f[set],邊境模式。匹配位于 set 內某個字符之前的一個空串,且這個位置的前一個字符不屬于 set。

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

      • 返回字符 s[i], s[i+1], ..., s[j] 的數字編碼
      • i 默認為 1,j 默認等于 i

      例:

      str = "abcdef"
      print(str:byte()) --> 97,'a' 的編碼值
      print(str:byte(2)) --> 98,'b' 的編碼值
      print(str:byte(2, 4)) -> 98 99  100
      

      string.char(...)

      • 接收整數作為字符的編碼值為參數,返回對應的字符

      例:

      print(string.char(97, 98, 99) --> abc
      

      string.dump(function [, strip])

      • 以字符串形式表示一個函數,并返回。返回的字符串可用 loadstring 加載。
      • strip 為真,表示去掉函數的調試信息(局部變量名,行號等)

      例:

      local function print_hello()
          print("hello world")
      end
      
      local f = string.dump(print_hello, true)
      print(f)
      
      local a = loadstring(f)
      print(type(a)) --> 'function'
      a() --> 'hello world'
      

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

      • 查找字符串 s 中第一個匹配到 pattern,返回匹配的起始和結束位置。找不到返回 nil
      • init 指定從何處開始查找,默認為 1。負值表示從倒數第幾個字符開始找,直到字符串結束。
      • plain 為真,則關閉模式匹配。

      例:

      str = "hello, world"
      print(string.find(str, "llo")) --> 3    5
      print(string.find(str, "world", -5)) --> 8  12
      print(string.find(str, "world", -4)) --> nil
      

      string.format(formating, ...)

      • 同 c 里的 sprintf,不支持 *, h, L, l, n, p
      • 增加 %q,將一個字符串格式化為兩個雙引號括起。

      例:

      str = 'a string with "quotes" and\nnew line'
      print(string.format("%q", str))
      

      string.gmatch(s, pattern)

      • 返回一個迭代器函數,該函數每次被調用時都會以 pattern 為模式對 s 作匹配,并返回捕獲到的值。

      例:

      s = "hello world from Lua"
      g = string.gmatch(s, "%a+")
      print(type(g)) --> 'function', g 是一個函數
      print(g()) --> 'hello',調用一次則進行一次匹配
      print(g()) --> 'world',返回第二次匹配的值
      
      s = "from=world, to=Lua"
      for k, v in string.gmatch(s, "(%w+)=(%w+)") do
          print(k, v) --> 打印捕獲到的值
      end
      

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

      • 將字符串中所有匹配的 pattern 都替換成 repl,并返回替換后的字符串。第二個返回值返回匹配次數。
      • pattern 中沒有設定捕獲則默認捕獲整個 pattern
      • 默認全部進行匹配

      例:

      s = "hello world, hello world, hello world"
      print(s:gsub("world", "sam")) --> hello sam, hello sam, hello sam   3
      
      • 如果有 n 參數,則只替換前 n 個匹配。

      例:

      s = "hello world, hello world, hello world"
      print(s:gsub("world", "sam", 1)) --> hello sam, hello world, hello world    1
      print(s:gsub("world", "sam", 2)) --> hello sam, hello sam, hello world  2
      
      • 若 repl 是字符串,則字符串直接替換。repl 中的 %d 表示第幾個捕獲到的子串。%0 表示整個匹配。%%表示單個百分號。

      例:

      s = "hello world, hello world, hello world"
      print(s:gsub("(%w+)", "%1 %1", 1)) --> hello hello world, hello world, hello world  1
      print(s:gsub("(%w+)%s*(%w+)", "%2 %1", 1)) --> world hello, hello world, hello world    1
      
      • 若 repl 是表,則每次匹配時都會用第一個捕獲值作為鍵值去查找這張表。

      例:

      x = {}
      x.hello = "HELLO"
      x.world = "WORLD"
      
      s = "hello world, hello world, hello world"
      print(s:gsub("(%w+)", x)) --> HELLO WORLD, HELLO WORLD, HELLO WORLD 6
      
      • 若 repl 是函數,則每次匹配時調用該函數,捕獲值作為參數傳入該函數。

      例:

      function x(str)
          return "sam"
      end
      
      s = "hello world, hello world, hello world"
      print(s:gsub("(%w+)", x)) --> sam sam, sam sam, sam sam 6
      
      • 表或函數的結果如果是 false 或 nil 則不操作,如果是字符串或數字,則進行替換。

      例:

      x = {}
      x.hello = "HELLO"
      
      s = "hello world, hello world, hello world"
      print(s:gsub("(%w+)", x)) --> HELLO world, HELLO world, HELLO world 6
      
      function x(str)
          return nil
      end
      
      s = "hello world, hello world, hello world"
      print(s:gsub("(%w+)", x)) --> hello world, hello world, hello world 6
      

      string.len(s)

      • 返回字符串長度

      例:

      print(string.len("hello, world")) --> 12
      

      string.lower(s)

      • s 中的大寫字符轉成小寫

      例:

      print(string.lower("HEllo, woRLD")) --> hello, world
      

      string.upper(s)

      • s 中的小寫字符轉成大寫

      例:

      print(string.upper("HEllo, woRLD")) --> HELLO, WORLD
      

      string.match(s, pattern[, init])

      • 在字符串中找到第一個匹配 pattern 部分,并返回捕獲值。找不到返回 nil。
      • init 指定搜索的起始位置。默認為 1,可以為負數。

      例:

      s = "hello world, hello world, hello world"
      print(string.match(s, "hello")) --> hello
      print(string.match(s, "wor%a+")) --> world
      

      string.rep(s, n[, sep])

      • 用 sep 連接 n 個 s,并返回
      • 默認 sep 為空,即沒有??? 分割符

      例:

      print(string.rep("hello", 2)) --> hellohello
      print(string.rep("hello", 2, ", ")) --> hello, hello
      

      string.reverse(s)

      • 反轉字符串 s

      例:

      print(string.reverse("hello")) --> olleh
      

      string.sub(s, i[, j])

      • 返回 s 的子串,從 i 開始,j 結束。
      • i 和 j 可以為負數。
      • j 默認為 -1,即到字符串結束。

      例:

      print(string.sub("hello", 2)) --> ello
      print(string.sub("hello", 2, 4)) --> ell
      

      string.pack(fmt, v1, v2, ...)

      string.packsize(fmt)

      string.unpack(fmt, s[, pos])

      posted @ 2015-12-07 13:17  sammei  閱讀(3432)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 自拍亚洲一区欧美另类| 精品无码国产日韩制服丝袜| 国语精品一区二区三区| 财经| 国产激情一区二区三区不卡| 日韩不卡一区二区三区四区 | 性姿势真人免费视频放| 亚洲国产成人综合精品| 4hu四虎永久免费地址ww416| 亚洲精品漫画一二三区| 99RE6在线观看国产精品| 激情五月开心婷婷深爱| 无限看片在线版免费视频大全| 亚洲熟妇无码av另类vr影视| 色综合人人超人人超级国碰| 国产精品久久久久孕妇| 极品尤物被啪到呻吟喷水| 91高清免费国产自产拍| 午夜三级成人在线观看| 国产乱码一区二区三区| 久播影院无码中文字幕| 亚洲一二三四区中文字幕| 国产99视频精品免费视频6| 免费无码一区无码东京热| 开心激情站开心激情网六月婷婷| 亚洲色大成网站WWW国产| 亚洲精品成人区在线观看| 中文在线а√天堂| 高潮潮喷奶水飞溅视频无码| 精品人妻少妇一区二区三区在线| 成人免费在线播放av| 亚洲成人精品一区二区中| 亚洲熟女乱综合一区二区三区 | 亚洲欧美成人一区二区在线电影| 长乐市| 国产成人一区二区三区在线| 色欲国产精品一区成人精品| 夜夜爽日日澡人人添| 久久九九日本韩国精品| 中文字幕国产精品资源| 中文字幕无码精品亚洲35|