gpt4 book ai didi

java - 从 JComboBox 列表中删除多余的空白和指定的行

转载 作者:太空宇宙 更新时间:2023-11-04 13:50:28 24 4
gpt4 key购买 nike

我正在使用jComboBox从文本文件中读取大数据 code .

文本文件大约有 100 列,我正在使用以下代码阅读必要的列:

(子字符串(12, 13)与 - “A、B、C、D、...” 相关,子字符串(58, 96)与 - “某些文本”相关)

jComboBox1.addItem(str.substring(12, 13) + str.substring(58, 96));

enter image description here

在输出中,我得到带有空行和空白空间的jComboBox。如图所示,我不需要读取标记有 "AAA" 的行(蓝线)和带有 comment 的行(红线)。

我想问是否可以删除多余的空格并排除标记为“AAA”的行?

提前谢谢您。

最佳答案

尝试这个答案:

for (String str : lines) {
if ( (!str.startsWith("AAA")) && (!str.substring(12, 13).equals(" ")) )
jComboBox1.addItem(str.substring(12, 13) + str.substring(58, 96));
}

关于java - 从 JComboBox 列表中删除多余的空白和指定的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30346759/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com