1. local function split(str, d) --str是需要查分的对象 d是分界符
  2. local lst = { }
  3. local n = string.len(str)--长度
  4. local start = 1
  5. while start <= n do
  6. local i = string.find(str, d, start) -- find 'next' 0
  7. if i == nil then
  8. table.insert(lst, string.sub(str, start, n))
  9. break
  10. end
  11. table.insert(lst, string.sub(str, start, i-1))
  12. if i == n then
  13. table.insert(lst, "")
  14. break
  15. end
  16. start = i + 1
  17. end
  18. return lst
  19. end

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

from: http://blog.csdn.net/heyuchang666/article/details/51700017

    1. function string.split(input, delimiter)
    2. input = tostring(input)
    3. delimiter = tostring(delimiter)
    4. if (delimiter=='') then return false end
    5. local pos,arr = 0, {}
    6. -- for each divider found
    7. for st,sp in function() return string.find(input, delimiter, pos, true) end do
    8. table.insert(arr, string.sub(input, pos, st - 1))
    9. pos = sp + 1
    10. end
    11. table.insert(arr, string.sub(input, pos))
    12. return arr
    13. end

Lua自己实现string.split功能的更多相关文章

  1. String.Split()功能

    我们在过去的教训 String.Join功能(http://blog.csdn.net/zhvsby/archive/2008/11/28/3404704.aspx).当中用到了String.SPli ...

  2. Lua 自定义函数string.split

    function string.split(str, delimiter)    if str==nil or str=='' or delimiter==nil then        return ...

  3. 实现c++的string的split功能

    今天写程序,遇到了一个要实现string.split()这个的一个函数.python里面有,qt里面有,c++里面没有.照着网上抄了一个,放在这里.有需要的时候直接拽过去用,否则老是写了小例子就扔,用 ...

  4. String.split()方法你可能不知道的一面

    一.问题 java中String的split()是我们经常使用的方法,用来按照特定字符分割字符串,那么我们看以下一段代码: public void splitTest() { String str = ...

  5. .NET 中String类功能分类概述

    一.比较功能 String.Compare: 成员函数 返回值 功能 String.Compare 小于零.零.大于零. 1.比较两个字符串的大小(按照一定规则) 2.比较两个字符串中子字符串的大小. ...

  6. lua中打印所以类型功能实现table嵌套table

    lua中打印所以类型功能实现 本人測试 number.string.bool.nil.table嵌套table.userdata没问题 共享一下有什么问题请拍砖 代码例如以下 cclog = func ...

  7. Lua 中的string库(字符串函数库)总结

    (字符串函数库)总结 投稿:junjie 字体:[增加 减小] 类型:转载 时间:2014-11-20我要评论 这篇文章主要介绍了Lua中的string库(字符串函数库)总结,本文讲解了string库 ...

  8. lua语言:string

    转载请注明来源:https://www.cnblogs.com/hookjc/ 字符串库函数string.len(s)          返回字符串s的长度:string.rep(s, n)      ...

  9. 字符串切分 String.Split 和 Regex.Split

    当切割字符串的是单个字符时可使用String.Split string strSample="ProductID:20150215,Categroy:Food,Price:15.00&quo ...

随机推荐

  1. 2分钟 windows下sublime text 3安装git插件:

    12:35 2015/11/182分钟 windows下sublime text 3安装git插件:推荐博客:http://blog.csdn.net/naola2001/article/detail ...

  2. HDU 4597 Play Game

    题目链接 什么都不想说,最近状态暴跌.. #include <cstdio> #include <cstring> #include <iostream> usin ...

  3. IOS 蓝牙相关-基础知识(1)

    蓝牙常见名称和缩写 MFI ======= make for ipad ,iphone, itouch 专们为苹果设备制作的设备 BLE ==== buletouch low energy,蓝牙4.0 ...

  4. 纪念逝去的岁月——C/C++二分查找

    代码 #include <stdio.h> int binarySearch(int iList[], int iNum, int iX, int * pPos) { if(NULL == ...

  5. iOS - JSON 数据解析

     iOS - JSON 数据解析 前言 NS_CLASS_AVAILABLE(10_7, 5_0) @interface NSJSONSerialization : NSObject @availab ...

  6. java实现BitMap

    package bitmap; public class BitMap { private byte[] bytes; public BitMap(byte[] bytes) { super(); t ...

  7. hdu A Bug's Life

    题目意思:给定一系列数对,例如a和b,表示a和b不是同一种性别,然后不断的给出这样的数对,问有没有性别不对的情况. 例如给定: 1    2 3    4 1    3 那这里就是说1和2不是同种性别 ...

  8. bootstrap学习笔记之一

    一.概要 bootstrap是最受欢迎的HTML.css和js框架,用于开发响应式布局,移动设备优先的WEB项目. 二.CSS部分 1.bootstrap已经设定了基本的全局样式,如font-fami ...

  9. 使用plupload做一个类似qq邮箱附件上传的效果

    公司项目中使用的框架是springmvc+hibernate+spring,目前需要做一个类似qq邮箱附件上传的功能,暂时只是上传小类型的附件 处理过程和解决方案都需要添加附件,处理过程和解决方案都可 ...

  10. css3 animation 实现环形路径平移动画

    注意 @keyframes to/from 的学习 <!DOCTYPE html> <html lang="en"> <head> <me ...