String expTitle=[Logged in as: admin@gmail.com , Logout?]
Scenario 1: From the above string want display only 'admin@gmail.com'
Program:
public class Split {
public static void main(String[] args) {
String title="[Logged in as: admin@gmail.com , Logout?]";
String[] one=title.split(": ");
System.out.println(one[1]);
String[] two=one[1].split(" ,");
System.out.println(two[0]);
}
}
output:
//here it will prints "admin@gmail.com"
++++++++++++++++++++++++++++++
Scenario 2: i want to print only 'cell movement'
public static void main(String[] args) {
String title="[cell movement, , ]";
String[] one=title.split("\\[");
System.out.println(one[1]);
String[] two=one[1].split(",");
System.out.println(two[0]);
}
output:
//here it will prints "cell movement"
++++++++++++
String str = "21= A=Person"; , here i want want split with "=" sign
public class Split_String_with_Equal_Sign {
public static void main(String[] args) throws InterruptedException {
String str = "21= A=Person";
String s[]=str.split("\\=");
String s2 = "";
for(int i=1;i<s.length;i++){
s2=s2+"="+s[i];
}
System.out.println(s2.replaceFirst("=", ""));
}
}
Output : A=Person
Scenario 1: From the above string want display only 'admin@gmail.com'
Program:
public class Split {
public static void main(String[] args) {
String title="[Logged in as: admin@gmail.com , Logout?]";
String[] one=title.split(": ");
System.out.println(one[1]);
String[] two=one[1].split(" ,");
System.out.println(two[0]);
}
}
output:
//here it will prints "admin@gmail.com"
++++++++++++++++++++++++++++++
Scenario 2: i want to print only 'cell movement'
public static void main(String[] args) {
String title="[cell movement, , ]";
String[] one=title.split("\\[");
System.out.println(one[1]);
String[] two=one[1].split(",");
System.out.println(two[0]);
}
output:
//here it will prints "cell movement"
++++++++++++
String str = "21= A=Person"; , here i want want split with "=" sign
public class Split_String_with_Equal_Sign {
public static void main(String[] args) throws InterruptedException {
String str = "21= A=Person";
String s[]=str.split("\\=");
String s2 = "";
for(int i=1;i<s.length;i++){
s2=s2+"="+s[i];
}
System.out.println(s2.replaceFirst("=", ""));
}
}
Output : A=Person
No comments:
Post a Comment