在 JTextArea 中查找空格后的第一个字符
Find first character in JTextArea after whitespaces
我想弄清楚如何为程序编写代码,如果用户在任何文本之前输入空格,则检测 JTextArea 中文本的开头位置。在所有空白程序执行 2 种方法之一之后,取决于文本的第一个符号。 Ml 如果第一个字符是“.”或“-”,否则 lm。这是我得到的:
output.setText("");
int i = 0;
char array[] = (input.getText()).toCharArray();
while(Character.toString(array[i]).equals("")){
i++;
}
if (array.length < i || !Character.toString(array[i]).equals(".") && !Character.toString(array[i]).equals("-")){
lm();
} else {
ml();
} return output.getText();
}
trim 字符串呢,这应该去掉字符串开头和结尾的空格
input.getText().trim()
trim public String trim()
Returns a string whose value is this string, with any leading and
trailing whitespace removed. If this String object represents an
empty character sequence, or the first and last characters of
character sequence represented by this String object both have codes
greater than '\u0020' (the space character), then a reference to this
String object is returned.
String msg = " this is a invaid spaced message ";
msg = msg.trim();
System.out.println(msg);
这会打印:
this is a invaid spaced message
我想弄清楚如何为程序编写代码,如果用户在任何文本之前输入空格,则检测 JTextArea 中文本的开头位置。在所有空白程序执行 2 种方法之一之后,取决于文本的第一个符号。 Ml 如果第一个字符是“.”或“-”,否则 lm。这是我得到的:
output.setText("");
int i = 0;
char array[] = (input.getText()).toCharArray();
while(Character.toString(array[i]).equals("")){
i++;
}
if (array.length < i || !Character.toString(array[i]).equals(".") && !Character.toString(array[i]).equals("-")){
lm();
} else {
ml();
} return output.getText();
}
trim 字符串呢,这应该去掉字符串开头和结尾的空格
input.getText().trim()
trim public String trim()
Returns a string whose value is this string, with any leading and trailing whitespace removed. If this String object represents an empty character sequence, or the first and last characters of character sequence represented by this String object both have codes greater than '\u0020' (the space character), then a reference to this String object is returned.
String msg = " this is a invaid spaced message ";
msg = msg.trim();
System.out.println(msg);
这会打印:
this is a invaid spaced message