我正在从 USB 驱动器将文本文件读入 Android 4.0 平板电脑,其中许多行以选项卡开头。作为语言的测验实用程序,典型的行是
[tab]an experience[crlf]
在拆分时,我有一个空数组元素,到目前为止我只能通过测试 if 来检测stringJustSplit[0].length( ) == 0
。这并不安全,因为长度是元素的属性,而不是它的属性。当然==""
,== null
并没有让我到任何地方。
我看到了这个RemoveEmptyEntries
选项,但我宁愿保留空元素,并且程序会有意地响应它们。
是否有声明可以处理它们?
日志产生:
---Array trial---(6229): Start
---Array trial---(6229): Located by length( )==0.
---Array trial---(6229): End
从这个方法:
while ((Fileline = buffered_reader.readLine( )) != null) {
line2array = Fileline.split("\\t");
String[] tester = new String[1];
String dummyStr = "|element1";
String[] emptyField = dummyStr.split("\\|");
if (true) {Log.v(T, "Start results");}
if (line2array[0] == emptyField[0]){Log.v(T, "Located by array element created similar way.");}
if (line2array[0] == tester[0]) {Log.v(T, "Located by comparison w just-made array.");}
if (line2array[0].length( ) == 0) {Log.v(T, "Located by length( ) == 0.");}
if (line2array[0] == "") {Log.v(T, "Located by zero-len string.");}
if (line2array[0] == null) {Log.v(T, "Located by null.");}
if (true) {Log.v(T, "End");}
}