gpt4 book ai didi

Java - 从文件中读取单词并删除双引号

转载 作者:行者123 更新时间:2023-11-29 07:34:13 26 4
gpt4 key购买 nike

我有一个包含很多行的文本文件,我需要从该行中找到一个特定的“单词”,删除双引号并将其打印到文本字段中。

    @FXML
private void findCFG(ActionEvent event) throws FileNotFoundException, IOException {
FileChooser fc = new FileChooser();
fc.setTitle("Open cfg file");
File cfgName = fc.showOpenDialog(null);
cfgPathLabel.setText(cfgName.getPath());



Scanner sc = new Scanner(cfgName);
while (sc.hasNextLine()) {
String word = sc.nextLine();
if (word.startsWith("volume ")) {
String[] splitter = word.split("volume ");
for (String s : splitter) {
volField.appendText(s);
}
}
}
}

我的结果

"0.1"

我想要的结果是

0.1

最佳答案

如果你想删除所有双引号那么你可以使用这个代码:

string=string.replaceAll("\"", "");

您正在用空替换所有双引号。使用变量字符串作为带双引号的字符串。

关于Java - 从文件中读取单词并删除双引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37978594/

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