local function split(str, d) --str是需要查分的对象 d是分界符 local lst = { } local n = string.len(str)--长度 local start = 1 while start <= n do local i = string.find(str, d, start) -- find 'next' 0 if i == nil then table.insert(lst, string.sub(str, start, n)) bre
function string.split(str, delimiter) if str==nil or str=='' or delimiter==nil then return nil end local result = {} for match in (str..delimiter):gmatch("(.-)"..delimiter) do table.insert(result, match) end r
今天在学习lua,熟悉项目代码的过程中,发现string.gsub好高级,所以在此mark下. 以下是lua5.1的官方文档介绍. string.gsub (s, pattern, repl [, n]) Returns a copy of s in which all occurrences of the pattern have been replaced by a replacement string specified by repl, which may be a string, a
在java doc里有 String[] java.lang.String.split(String regex) Splits this string around matches of the given regular expression. This method works as if by invoking the two-argument split method with the given expression and a limit argument of zero. Tra
场景 出于业务考虑,将多个字符串拼接起来时,使用的分隔符是;,;.如果要将这样一个拼接来的字符串分割成原本的多个字符串时,就需要使用到jdk自带的split()方法.不过因为公司的编程规范,改为使用了Apache工具类的StringUtils.split(). 之后就发现,当被拼接的字符串里含有;或,时,就会出现分割不正确的问题. 具体例子 下面的代码,使用了上述的两种split方法,猜猜结果是什么. public class Test { public static void main(fin
代码: String str = "the music made it hard to concentrate"; String delims = "[ ]+"; String[] tokens = str.split(delims); 结果为: the, music, made, it, hard, to, concentrate 原因: String.split(String regex):参数是一个正则表达式 转自:http://pages.cs.wisc.e