// 用指定字符或字符串分割输入字符串,返回包含分割结果的数组

// @function [parent=#string] split

// @param string input 输入字符串

// @param string delimiter 分割标记字符或字符串

// @return array#array  包含分割结果的数组

/*

用指定字符或字符串分割输入字符串,返回包含分割结果的数组

local input = "Hello,World"

local res = string.split(input, ",")

-- res = {"Hello", "World"}

local input = "Hello-+-World-+-Quick"

local res = string.split(input, "-+-")

-- res = {"Hello", "World", "Quick"}

*/

function string.split(input, delimiter)

    input = tostring(input)

    delimiter = tostring(delimiter)

    if (delimiter=='') then return false end

    local pos,arr = , {}

    -- for each divider found

    for st,sp in function() return string.find(input, delimiter, pos, true) end do

        table.insert(arr, string.sub(input, pos, st - ))

        pos = sp + 

    end

    table.insert(arr, string.sub(input, pos))

    return arr

end

https://blog.csdn.net/heyuchang666/article/details/52403087

Lua 用指定字符或字符串分割输入字符串,返回包含分割结果的数组的更多相关文章

  1. 写出一个程序,接受一个由字母和数字组成的字符串,和一个字符,然后输出输入字符串中含有该字符的个数。不区分大小写。java算法

    知识点一:equalsIgnore 1.使用equals( )方法比较两个字符串是否相等.它具有如下的一般形式: boolean equals(Object str) 这里str是一个用来与调用字符串 ...

  2. js获取指定字符前/后的字符串简单实例

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  3. js 截取某个字符前面或者后面的字符串

    /* string 字符串; str 指定字符; split(),用于把一个字符串分割成字符串数组; split(str)[0],读取数组中索引为0的值(第一个值),所有数组索引默认从0开始; */ ...

  4. C#字符串处理 及字符串格式化

    本文来自:http://www.cnblogs.com/xuerongli/archive/2013/03/23/2976669.html string字符串是char的集合,而char是Unicod ...

  5. php把字符串指定字符分割成数组

    <?php $str="1|2|3|4|5|"; $var=explode("|",$str); print_r($var); ?> $var=ex ...

  6. 请求大神,C#如何截取字符串中指定字符之间的部分 按指定字符串分割 一分为二 c# 去除字符串中的某个已知字符

    string stra = "abcdefghijk";string strtempa = "c";string strtempb = "j" ...

  7. C语言实现split以某个字符分割一个字符串

    方式一: 使用strtok # include <string.h> # include <stdio.h> void split(char *src,const char * ...

  8. JS中同步显示并分割输入的数字字符串

    题目比较晦涩,来张图来说明要表达的效果: 第一张图的效果就是,用户输入一个数字,上面就显示一个大层,然后显示输入的数字,并把数字用空格按照每四位分割出来.好像在建行的网上银行上面就有这种效果.第二个图 ...

  9. PHP操作字符串 截取指定长度字符 移除字符串两侧 左侧 右侧指定字符 或空白字符 替换字符

    trim() trim() 函数移除字符串两侧的空白字符或其他预定义字符. <?php $str = "Hello World!"; echo $str . "&l ...

随机推荐

  1. Anaconda spyder 设置tab键为2个空格

    tool -> Preference->

  2. linux ping: unknown host www.baidu.com

    在虚拟机中使用CentOS6.5时,ping www.baidu.com出现报错信息:“ping: unknown hostwww.baidu.com”,虚拟机和物理机网络连接是NAT方式,物理机访问 ...

  3. 在CentOS上安装Python3的三种方法

    Centos7默认自带了Python2.7版本,但是因为项目需要使用Python3.x你可以按照此文的三个方法进行安装. 注:本文示例安装版本为Python3.5, 一.Python源代码编译安装 安 ...

  4. HTML表单简单练习

    代码: <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <tit ...

  5. CentOS7中GreVPN的配置

    目前只实现了三层的GRE隧道,但其实二层也可以实现的,但是没有找到很好的方法,待研究 环境如下: host A :  121.207.22.123 host B: 111.2.33.28 1. 在ho ...

  6. (转)批量插入sql语句

    为了减少数据库连接的I/O开销,一般会把多条数据插入放在一条SQL语句中一次执行.1.INSERT INTO TABLE(col1, col2) VALUES(val11, val12), (val2 ...

  7. Why ngx-uploader doesn't like to cooperate with .net core 2.x?

    The POST action seems to have no effect on the .net core controller. If you put [IgnoreAntiforgeryTo ...

  8. ansible批量管理

    编写批量安装脚本 [root@m01 scripts]# vim install.sh for ip in $* do echo "=======start install to $ip = ...

  9. Python 上下文管理协议中的__enter__和__exit__基本理解

    所谓上下文管理协议,就是咱们打开文件时常用的一种方法:with __enter__(self):当with开始运行的时候触发此方法的运行 __exit__(self, exc_type, exc_va ...

  10. REST AND SOAP

    REST,即Representational State Transfer的缩写.直接翻译的意思是"表现层状态转化".它是一种互联网应用程序的API设计理念:URL定位资源,用HT ...