如何使用String.split(",")导入CSV文件,而不会由于空白字段而缩短数组? [英] How to import CSV File using String.split(",") without having the array shortened due to blank fields?

查看:157
本文介绍了如何使用String.split(",")导入CSV文件,而不会由于空白字段而缩短数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,当我导入CSV文件行 String.split(,)如果有一行看起来像 foo ,, bar ,, fizz ,,,该方法返回长度为5的数组,看起来像 [foo,,bar, ,fizz] 。如何获取该方法返回一个长度为8的数组 [foo,,bar,

Currently, when I import the CSV file line by line with String.split(",") if there is a line that looks like "foo,,bar,,fizz,,," the method returns an array of length 5, which looks like ["foo", "", "bar, "", "fizz"]. How do I get the method to return an array of length 8 being ["foo", "", "bar", "", "fizz, "", "", ""]?

推荐答案

还有另一个 overload of split 实现:

There is another overload of split that achieves that:

string.split(",", -1);

这篇关于如何使用String.split(",")导入CSV文件,而不会由于空白字段而缩短数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆