如何删除字符串值两边的方括号 [英] How to remove square brackets on either side of string value
问题描述
当我在表格上选择一行时,它将以字符串形式打印出所选项目,如图所示.如何从弦的两边移除方括号.
When I choose a row on the table it prints out the selected item in a string as shown. How do I remove the square brackets from either side of the string.
下面是我的代码,用数据填充TextFields.您可以看到它已成功填充,但是带有[].
Below is my code to populate TextFields with the data. You can see it populates successfully but with the [].
表和输出
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
应该是Object
.假设它是SchoolInfo
的对象,其变量为String code
,String name
,String lecturer
,int year
和int semester
.您的Object
应该具有Getters
和Setters
.您应该做类似的事情.
You newValue
should be an Object
. Let's say it's an object of SchoolInfo
with variables of String code
, String name
, String lecturer
, int year
, and int semester
. Your Object
should have Getters
and Setters
. You should do something like.
警告:其他一些答案可能会完成任务,但不是很好的主意.您尝试处理此数据的方式是个坏主意.
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);
});
这篇关于如何删除字符串值两边的方括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!