刚刚写的一个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 ...
随机推荐
- [国家集训队]happiness 最小割 BZOJ 2127
题目描述 高一一班的座位表是个n*m的矩阵,经过一个学期的相处,每个同学和前后左右相邻的同学互相成为了好朋友.这学期要分文理科了,每个同学对于选择文科与理科有着自己的喜悦值,而一对好朋友如果能同时选文 ...
- PHP删除目录下的空目录
function rm_empty_dir($path){ if(is_dir($path) && ($handle = opendir($path))!==false){ ...
- Android studio 混淆打包
AndroidStudio中的项目可以用compile的形式引入github上的开源项目,可以引用module,而不一定都要用libs文件夹中添加jar包的形式. 在最终realease打包时,混淆的 ...
- react PropTypes 与 DefaultProps
PropTypes 与 DefaultProps import React ,{ Component } from 'react'; import PropTypes from 'prop-types ...
- C#空接合操作符——??
操作符: ?? 用法:C = A ?? B; 解释:if(A != null){ C=A;} else{C=B} 类似三元运算符 :? 例子: Int32? num1=null; Int32? ...
- Codeforces Round #520 (Div. 2) B math(素数因子的应用)
题意: 给出一个n ; 有两个操作: 1,mul A , n=n*A : 2,sqrt() , n=sqrt(n) 开更出来必须是整数 : 求出经过这些操作后得出的最小 n , 和 ...
- Flask&&人工智能AI --5 Flask-session、WTForms、数据库连接池、Websocket
未完待续.... DButils 什么是数据库连接池 数据库连接池负责分配.管理和释放数据库连接,它允许应用程序重复使用一个现有的数据库连接,而不是再重新建立一个:释放空闲时间超过最大空闲时间的数据库 ...
- Nmap工具使用
Nmap是一款网络扫描和主机检测的非常有用的工具. Nmap是不局限于仅仅收集信息和枚举,同时可以用来作为一个漏洞探测器或安全扫描器.它可以适用于winodws,linux,mac等操作系统.Nmap ...
- my17_Mysql 主从切换
注意事项: 从库提升为主库read_only要设置为OFF原主库改为从库后,read_only要设置ONread_only=ON并不能对root生效,确保root不会进行数据写入从主库进行 flush ...
- Mybatis学习笔记10 - 动态sql之if判断
示例代码: 接口定义: package com.mybatis.dao; import com.mybatis.bean.Employee; import java.util.List; public ...