gpt4 book ai didi

java - 如何删除字符串值两侧的方括号

转载 作者:行者123 更新时间:2023-12-01 16:46:42 24 4
gpt4 key购买 nike

当我选择表格中的一行时,它会打印出字符串中的所选项目,如图所示。如何删除字符串两侧的方括号。

下面是我用数据填充 TextFields 的代码。您可以看到它已成功填充,但带有 []。

表格和输出

the table and output

tableView.getSelectionModel().selectedItemProperty().addListener((v, oldValue, newValue) -> {
String input = newValue.toString();
String[] str_array = input.split(", ");
String code = str_array[0];
String name = str_array[1];
String lecturer = str_array[2];
String year = str_array[3];
String semester = str_array[4];

codeInput.setText(code);
nameInput.setText(name);
lectureInput.setText(lecturer);
yearInput.setText(year);
semesterInput.setText(semester);
System.out.println(input);
});

最佳答案

您的newValue应该是一个对象。假设它是一个 SchoolInfo 对象,其变量为 String codeString nameString Lecturer整年整学期。您的对象应该有GettersSetter。你应该做类似的事情。

警告:其他一些答案可能可以完成工作,但都是非常糟糕的主意。您尝试处理这些数据的方式是一个坏主意。

tableView.getSelectionModel().selectedItemProperty().addListener((v, oldValue, newValue) -> {
SchoolInfo tempSchoolInfo = (SchoolInfo)newValue;

String code = tempSchoolInfo.getCode();
String name = tempSchoolInfo .getName();
String lecturer = tempSchoolInfo.getLecturer;
int year = tempSchoolInfo.getYear();
int semester = tempSchoolInfo.getSemester();

codeInput.setText(code);
nameInput.setText(name);
lectureInput.setText(lecturer);
yearInput.setText(Integer.toString(year));
semesterInput.setText(Integer.toString(semester));
System.out.println(input);
});

关于java - 如何删除字符串值两侧的方括号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49174299/

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