刚刚写的一个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 ...
随机推荐
- Gym - 101845K 排序+概率
The UNAL programming coaches have lost a bet, they bet the 6 UNAL teams would occupy the first six p ...
- CF912D Fishes 期望
题意翻译 Description 有一个长为nnn ,宽为mmm 的鱼缸,还有一个边长为rrr 的正方形渔网.你可以往鱼缸里放kkk 条鱼,问用渔网随机在浴缸里捞鱼的最大期望是多少.不懂什么是期望的自 ...
- pytorch实现depthwise convolution
深度分离卷积是Xception这个模型中提出来的(不太确定,但肯定是它让这个概念为大众周知),具体来说分为两步,depthwise conv和pointwise conv,前者对输入特征图的每个通道进 ...
- SprimgMVC学习笔记(七)—— 上传图片
一.配置虚拟目录 在tomcat上配置图片虚拟目录,在tomcat下conf/server.xml中添加: <Context docBase="D:\upload\temp" ...
- sharepoint_study_9
描述:sharepoint2013 网站修改导航条标题 SuiteBartext 图示: 解决: 管理员身份进sharepoint powershell ,依次敲入搞定1. $app = Get-SP ...
- 9.ORM数据访问
1.Spring对ORM的支持 ORM : 对象关系映射(Object Relational Mapping)是一种为了解决面向对象与关系数据库存在的互不匹配的现象的技术基于ORM的数据持久层框架有: ...
- U盘中病毒了
往U盘里拷东西的时候突然发现一个后缀名为exe图标却是文件夹的图标的文件.大概二三百K 按类型排序之后发现好几个这样的文件,大小都是一模一样的,名字分别跟我U盘里原先的文件夹对应,原本的文件夹都被设置 ...
- Flex布局教程
一.Flex布局是什么? Flex 是 Flexible Box 的缩写,意为"弹性布局",用来为盒状模型提供最大的灵活性.任何一个容器都可以指定为 Flex 布局. .box{ ...
- 以sqlplus管理员权限登陆oracle
>>sqlplus username/password@orcl as sysdba 切记切记
- 3DMAx Panda Directx Exporter 导出 X插件
Panda Directx Exporter 下载地址 http://www.andytather.co.uk/Panda/directxmax_downloads.aspx 将下载的文件解压后,放到 ...