You can use split()
function to split the sentences based on delimiter \n
and store them in an array. Then by iterating the array, you can access each string:
public static void main(String[] args) {
String Text="Bank name Some Thing \n Reminder is Some Thing \n Date Some";
String[] sentences = Text.split("\n");
for (String s : sentences){
System.out.println(s.trim());
}
}
Related method's doc page is here.
Since there are additional spaces around delimiter, you can use trim
method to remove them.
If you want to assign the values to different variables as mentioned in your question, you can do it as follows:
String T1 = sentences[0].trim();
String T2 = sentences[1].trim();
String T3 = sentences[3].trim();
You should also follow Java naming conventions e.g. the name of the variables should be t1
, t2
, and t3
instead of T1
, T2
, and T3
.