如何从字符串值中获取前两个单词
How to get first two word from a string value
我有两个字符串:"I am a Beginner", "Hello Dear App Developer"
如何使用 Java "I am" "Hello Dear"
仅获取前两个词
String TextOne = "I am a Beginner"
String TextTwo = "Hello Dear App Developer"
I need only "I am" and "Hello Dear"
您可以通过 space(" ")
拆分字符串
String TextOne = "I am a Beginner";
String[] strList = TextOne.split(" "); //["I", "am", "a", "Beginner"]
String finalTextOne = strList[0] + " " + strList[1];
Log.e("finalTextOne: ", finalTextOne); // It will print "I am"
我有两个字符串:"I am a Beginner", "Hello Dear App Developer" 如何使用 Java "I am" "Hello Dear"
仅获取前两个词String TextOne = "I am a Beginner"
String TextTwo = "Hello Dear App Developer"
I need only "I am" and "Hello Dear"
您可以通过 space(" ")
拆分字符串String TextOne = "I am a Beginner";
String[] strList = TextOne.split(" "); //["I", "am", "a", "Beginner"]
String finalTextOne = strList[0] + " " + strList[1];
Log.e("finalTextOne: ", finalTextOne); // It will print "I am"