Split string to make a subString in java or (Android)
1. String replace function
String str = "Hello^how are you";
String newStr = str.replaceAll("[^]+", "1");
2. To split a String in java at particular character
Write these lines of code which are given below
String str = "hello, goachivers";
String[] output = str.split(",");String str1= output[0];
String str2=output[1];
To print the vale of str1 and str2
For java:
System.out.println(output[0]);
System.out.println(output[1]);
For Android
Toast.makeText(getApplicationContext(),"str1:"+str1, Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(),"str2:"+str2, Toast.LENGTH_SHORT).show();
Output :
str1:hello
str2:goachivers
Comments
Post a Comment