刚刚写的一个lua下解释csv的工具。
csvtool = {} function csvtool:csv2table(filename)
if type(filename) ~= "string" or filename == "" then
print("the filename is not a string or a empty string")
return nil
end
local filepath = cc.FileUtils:getInstance():fullPathForFilename(filename)
local filedate = cc.FileUtils:getInstance():getStringFromFile(filepath)
print(filedate)
local dataByLine = Split(filedate,'\n')
local titleArray = Split(dataByLine[],',')
local lineIndex =
local titleSize = table.getn(titleArray)
local returnTable = {}
for line = ,table.getn(dataByLine)- do
local dataByLien_split = Split(dataByLine[line],',')
returnTable[lineIndex] = {}
for i = ,titleSize do
returnTable[lineIndex][titleArray[i]] = dataByLien_split[i]
end
lineIndex = lineIndex+
end
return returnTable
end function csvtool:returnCsvTableTitle(csvtable)
local titleTable = {}
local titleIndex =
for key, var in pairs(csvtable[]) do
titleTable[titleIndex] = key
titleIndex = titleIndex +
end
return titleTable
end function csvtool:returnScvTitleIndex(csvtable,findtitlename)
if type(csvtable) ~= "table" or table.getn(csvtable) == then
print("the argment 1 is not a csvtable or is a empty table")
return nil
end
if findtitlename == "" or type(findtitlename) ~= "string" then
print("the findtitlename is a empty string or the type not a string")
return nil
end
local csvtitle = csvtool:returnCsvTableTitle(csvtable)
for key, var in pairs(csvtitle) do
if var == findtitlename then
return key
end
end
return nil
end function csvtool:findLineByKeyAndValue(csvtable,key,value)
if type(csvtable) ~= "table" or table.getn(csvtable) == then
print("the argment 1 is not a csvtable or is a empty table")
return nil
end
if type(key) ~= "string" or key == "" then
print("the argment 2 is not a string or is a empty string")
return nil
end
if csvtable[][key] == nil then
print("the key is not found in csvtable")
return nil
end
local linereturn = {}
value = tostring(value)
local isFound = false
for k, v in pairs(csvtable) do
if v[key] == value then
isFound = true
table.insert(linereturn,v)
end
end
if isFound then
return linereturn
else
print("not found this key-value item")
return nil
end
end function csvtool:findoneLineByKeyAndValue(csvtable,key,value)
if type(csvtable) ~= "table" or table.getn(csvtable) == then
print("the argment 1 is not a csvtable or is a empty table")
return nil
end
if type(key) ~= "string" or key == "" then
print("the argment 2 is not a string or is a empty string")
return nil
end
if csvtable[][key] == nil then
print("the key is not found in csvtable")
return nil
end
local linereturn = {}
value = tostring(value)
for k, v in pairs(csvtable) do
if v[key] == value then
return v
end
end
print("not found this key-value item")
return nil
end function csvtool:findValueByOneKeyAndValue(csvtable,findkey,anotherkey,anothervalue) --find a value by another key-value
if type(csvtable) ~= "table" or table.getn(csvtable) == then
print("the argment 1 is not a csvtable or is a empty table")
return nil
end
if type(findkey) ~= "string" or findkey == "" then
print("the argment 2 is not a string or is a empty string")
return nil
end
if csvtable[][findkey] == nil then
print("the find key is not found in csvtable")
return nil
end
if csvtable[][anotherkey] == nil then
print("the another key is not found in csvtable")
return nil
end
local finditem = self:findoneLineByKeyAndValue(csvtable,anotherkey,anothervalue)
local foundvalue = finditem[findkey]
return foundvalue --string
end function csvtool:returnOneRowByKey(csvtable, rowkey)
if type(csvtable) ~= "table" or table.getn(csvtable) == then
print("the argment 1 is not a table or a empty table")
return nil
end
if type(rowkey) ~= "string" or rowkey == "" then
print("the argment 2 is not a string or is a empty string")
return nil
end
if csvtable[][rowkey] == nil then
print("the table is not have the rowkey row")
return nil
end
local returnRow = {}
local returnRowIndex =
for k, v in pairs(csvtable) do
returnRow[returnRowIndex] = v[rowkey]
returnRowIndex = returnRowIndex +
end
return returnRow
end function csvtool:getcsvsize(filename)
local csvtable = self:csv2table(filename)
local size = table.getn(csvtable)
return size
end function Split(szFullString, szSeparator)
local nFindStartIndex =
local nSplitIndex =
local nSplitArray = {}
while true do
local nFindLastIndex = string.find(szFullString, szSeparator, nFindStartIndex)
if not nFindLastIndex then
nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, string.len(szFullString))
break
end
nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, nFindLastIndex - )
nFindStartIndex = nFindLastIndex + string.len(szSeparator)
nSplitIndex = nSplitIndex +
end
return nSplitArray
end
刚刚写的一个lua下解释csv的工具。的更多相关文章
- 开源一个IE下获取XPath小工具,支持32/64位
背景是曾经友情支持了测试组一小段时间,发现他们使用selenium做页面的自动化测试,需要用到XPath,但IE下没有获取XPath的工具,只能在Firefox和chrome下获取,步骤还比较麻烦.而 ...
- rinetd 一个linux下的端口转发工具
inux下使用iptables实现端口转发,配置较为复杂,使用rinetd工具可以实现快速配置和修改端口转发. 例:本机ip:1.1.1.1 需要实现访问本机的8080端口,自动转发到2.2.2.2 ...
- 自己写了一个解析json为table的工具类
还需要完善的包括,css的封装,触发事件,数据的获得处理: <!DOCTYPE html> <html> <head> <meta charset=" ...
- cron Linux下的定时执行工具
说明:测试平台 Ubuntu 16.04.4 LTS cron是一个Linux下的定时执行工具,可以在无需人工干预的情况下运行作业.所以,在Linux中,周期性执行的任务一般由cron这个守护进程来 ...
- linux 下的 crontab 定时任务工具
以下内容转自:https://www.cnblogs.com/longjshz/p/5779215.html 在LINUX中,周期执行的任务一般由cron这个守护进程来处理[ps -ef|grep c ...
- lLinux 下 Stress 压力测试工具
作者信息 邮箱:sijiayong000@163.com Q Q:601566386 Stress是什么 stress是一个linux下的压力测试工具,专门为那些想要测试自己的系统,完全高负荷和监督这 ...
- Tools - Windows系统下的命令行工具Cmder
cmder简介 官网:http://cmder.net/ GitHub:https://github.com/cmderdev/cmder Cmder是一个windows下的命令行工具,用来替代win ...
- Cordova webapp实战开发:(6)如何写一个iOS下获取APP版本号的插件?
上一篇我们学习了如何写一个Andorid下自动更新的插件,我想还有一部分看本系列blog的开发人员希望学习在iOS下如何做插件的吧,那么今天你就可以来看看这篇文字了. 本次练习你能学到的 学习如何获取 ...
- Cordova webapp实战开发:(5)如何写一个Andorid下自动更新的插件?
在 <Cordova webapp实战开发:(4)Android环境搭建>中我们搭建好了开发环境,也给大家布置了调用插件的预习作业,做得如何了呢?今天我们来学一下如何自己从头建立一个And ...
随机推荐
- 统计元音(stringstream的-应用)
Problem Description 统计每个元音字母在字符串中出现的次数. Input 输入数据首先包括一个整数n,表示测试实例的个数,然后是n行长度不超过100的字符串. Output ...
- 小程序不在以下 request 合法域名列表中
我们如果是正式上线可以在小程序后台配置合法域名,必须是https 测试时我们可以关闭验证 在 设置 - 项目设置 里勾选不校验https 和 TLS
- 3. mybatis # 与 $ 的区别
mybatis # 与 $ 的区别 1.# % 号必须写在test中 应用场景:模糊查询 配置文档mapper.xml <select id="selectBlogByTitle&qu ...
- 09-排序3 Insertion or Heap Sort (25 分)
According to Wikipedia: Insertion sort iterates, consuming one input element each repetition, and gr ...
- php内置web server
今天刚开始正式学习PHP(之前有一点了解),推荐学习的网站是w3school.一开始不知道tomcat服务器不支持PHP脚本,直接把.php文件放到tomcat里面去运行,结果嵌入的php代码段没有什 ...
- Xshell上Linux上传下载文件
Xshell上的Linux想要进行文件的上传和下载可以使用以下命令: #rz //将本地的文件上传到Linux服务器,执行后会弹出选择文件的框 #sz filename //将 filename 这个 ...
- Mybatis学习笔记12 - 动态sql之choose(when otherwise)标签
choose (when, otherwise):分支选择:带了break的swtich-case 示例代码: 接口定义: package com.mybatis.dao; import com.my ...
- eclipse 分屏显示同一文件
某个类很大,可能有数千行.当你想要将类开头部分与中间或者靠后的部分进行对比时,请follow如下步骤: Window -> Editor -> Toggle Split Editor (C ...
- 表单注册及自定义validate手机验证码验证实例
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8& ...
- Android 中实现分享和第三方登陆---以新浪微博为例
第三方登陆和分享功能在目前大部分APP中都有,分享功能可以将自己觉得有意义的东西分享给身边的朋友,而第三方登陆可以借助已经有巨大用户基础的平台(如QQ和新浪微博)的账号,让用户在使用自己APP的时候不 ...