I can get the input into one string. Like that:
input = (EditText)findViewById(R.id.input1);
text = (TextView)findViewById(R.id.text1);
String value = input.getText().toString();
text.setText(value);
But how can I get the text of the input and store each word in a single variable? I searched very long but nothing worked.
Use toCharArray()
method of String class
char[] values = value.toCharArray();
EXAMPLE
String value = "Hello";
char[] values = value.toCharArray();
for(char c: values){
System.out.println(" "+ c);
}
OUTPUT
H
e
l
l
o
Use split(String regex)
method
EXAMPLE
String value = "Hello My Friends";
String[] values = value.split(" ");
for(String c: values){
System.out.println(" "+ c);
}
OUTPUT
Hello
My
Friends
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments