Lua自己实现string.split功能
- 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))
- break
- end
- table.insert(lst, string.sub(str, start, i-1))
- if i == n then
- table.insert(lst, "")
- break
- end
- start = i + 1
- end
- return lst
- end
另一种:用指定字符或字符串分割输入字符串,返回包含分割结果的数组:
from: http://blog.csdn.net/heyuchang666/article/details/51700017
- function string.split(input, delimiter)
- input = tostring(input)
- delimiter = tostring(delimiter)
- if (delimiter=='') then return false end
- local pos,arr = 0, {}
- -- 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 - 1))
- pos = sp + 1
- end
- table.insert(arr, string.sub(input, pos))
- return arr
- end
Lua自己实现string.split功能的更多相关文章
- String.Split()功能
我们在过去的教训 String.Join功能(http://blog.csdn.net/zhvsby/archive/2008/11/28/3404704.aspx).当中用到了String.SPli ...
- Lua 自定义函数string.split
function string.split(str, delimiter) if str==nil or str=='' or delimiter==nil then return ...
- 实现c++的string的split功能
今天写程序,遇到了一个要实现string.split()这个的一个函数.python里面有,qt里面有,c++里面没有.照着网上抄了一个,放在这里.有需要的时候直接拽过去用,否则老是写了小例子就扔,用 ...
- String.split()方法你可能不知道的一面
一.问题 java中String的split()是我们经常使用的方法,用来按照特定字符分割字符串,那么我们看以下一段代码: public void splitTest() { String str = ...
- .NET 中String类功能分类概述
一.比较功能 String.Compare: 成员函数 返回值 功能 String.Compare 小于零.零.大于零. 1.比较两个字符串的大小(按照一定规则) 2.比较两个字符串中子字符串的大小. ...
- lua中打印所以类型功能实现table嵌套table
lua中打印所以类型功能实现 本人測试 number.string.bool.nil.table嵌套table.userdata没问题 共享一下有什么问题请拍砖 代码例如以下 cclog = func ...
- Lua 中的string库(字符串函数库)总结
(字符串函数库)总结 投稿:junjie 字体:[增加 减小] 类型:转载 时间:2014-11-20我要评论 这篇文章主要介绍了Lua中的string库(字符串函数库)总结,本文讲解了string库 ...
- lua语言:string
转载请注明来源:https://www.cnblogs.com/hookjc/ 字符串库函数string.len(s) 返回字符串s的长度:string.rep(s, n) ...
- 字符串切分 String.Split 和 Regex.Split
当切割字符串的是单个字符时可使用String.Split string strSample="ProductID:20150215,Categroy:Food,Price:15.00&quo ...
随机推荐
- 2分钟 windows下sublime text 3安装git插件:
12:35 2015/11/182分钟 windows下sublime text 3安装git插件:推荐博客:http://blog.csdn.net/naola2001/article/detail ...
- HDU 4597 Play Game
题目链接 什么都不想说,最近状态暴跌.. #include <cstdio> #include <cstring> #include <iostream> usin ...
- IOS 蓝牙相关-基础知识(1)
蓝牙常见名称和缩写 MFI ======= make for ipad ,iphone, itouch 专们为苹果设备制作的设备 BLE ==== buletouch low energy,蓝牙4.0 ...
- 纪念逝去的岁月——C/C++二分查找
代码 #include <stdio.h> int binarySearch(int iList[], int iNum, int iX, int * pPos) { if(NULL == ...
- iOS - JSON 数据解析
iOS - JSON 数据解析 前言 NS_CLASS_AVAILABLE(10_7, 5_0) @interface NSJSONSerialization : NSObject @availab ...
- java实现BitMap
package bitmap; public class BitMap { private byte[] bytes; public BitMap(byte[] bytes) { super(); t ...
- hdu A Bug's Life
题目意思:给定一系列数对,例如a和b,表示a和b不是同一种性别,然后不断的给出这样的数对,问有没有性别不对的情况. 例如给定: 1 2 3 4 1 3 那这里就是说1和2不是同种性别 ...
- bootstrap学习笔记之一
一.概要 bootstrap是最受欢迎的HTML.css和js框架,用于开发响应式布局,移动设备优先的WEB项目. 二.CSS部分 1.bootstrap已经设定了基本的全局样式,如font-fami ...
- 使用plupload做一个类似qq邮箱附件上传的效果
公司项目中使用的框架是springmvc+hibernate+spring,目前需要做一个类似qq邮箱附件上传的功能,暂时只是上传小类型的附件 处理过程和解决方案都需要添加附件,处理过程和解决方案都可 ...
- css3 animation 实现环形路径平移动画
注意 @keyframes to/from 的学习 <!DOCTYPE html> <html lang="en"> <head> <me ...