我从EditText中获取用户输入,将其反转,然后在TextView中输出。除了输入的字符串输出外,一切正常,例如
StackOverflow is a community of awesome programmers!
变成
!programmers awesome of community a is StackOverflow
.
-
当字符串倒转时,将第一个字母大写:
Programmers awesome of community a is StackOverflow
-
programmers awesome of community a is StackOverflow !
我使用下面的代码来反转字符串:
String[] nowTyping = input.getText().toString().split(" ");
ArrayList<String> wordArray = new ArrayList<>();
for (String word : nowTyping) {
wordArray.add(0, word);
}
String invertedSentence = TextUtils.join(" ", wordArray);
output.setText(invertedSentence);
我已经试过了
android:inputType="textCapWords"
把第一个字母大写,但似乎不起作用。
谢谢你的时间。