-1

i want to be able to split a TextView into a new string every time there is a @.

E.g. if TextView says " hello where are you @ i am @ school"

Output: string one = "@ i am "

String two = "@ school"

I have tried

String[] separated = text.getText().toString().split("@ · ");
tv.setText("first " + separated[0] + " next " +  separated[1] +  " next " +  separated[2] + " next " + separated[3]);
user3541743
  • 61
  • 1
  • 9
  • The split() method accepts only the delimiter, meaning that your should write `text.getText().toString.split("@")` to correctly split your string – mittelmania Aug 27 '14 at 18:08

1 Answers1

5
String input = "hello where are you @ i am @ school"
String[] split = input.split("@");

split[0] = hello where are you
split[1] =  i am 
split[2] =  school

If your question is more about including the @ symbol, How to split a string, but also keep the delimiters?

Community
  • 1
  • 1
r2DoesInc
  • 3,759
  • 3
  • 29
  • 60