我正在尝试解析CSV文件并使用SQL命令自动为其创建表.CSV中的第一行显示列标题.但我需要推断每一个的列类型.
Ruby中是否有任何函数可以在每个字段中找到内容的类型.例如,CSV行:
"12012", "Test", "1233.22", "12:21:22", "10/10/2009"
Run Code Online (Sandbox Code Playgroud)
应该产生类似的类型
['integer', 'string', 'float', 'time', 'date']
Run Code Online (Sandbox Code Playgroud)
谢谢!
这是我现在使用的代码片段:
def countOccurences(a, b)
#counts the number of occurences of a in b
count=0
cur=0
while cur < b.length do
temp=b.index(a, cur)
if temp == nil
break
end
count=count+1
cur=temp+a.length
end
return count
end
Run Code Online (Sandbox Code Playgroud)
是否有任何Ruby功能可以做到这一点?任何功能等同?还是更好的?