I was trying to split my string using ± (alt + 0177) sign, but it dos't detect it. I also tried indexOf() but its not work
String myString = "20±1";
if(myString.indexOf('±')>-1){
System.out.println("We are in here.........");
}
I was trying to split my string using ± (alt + 0177) sign, but it dos't detect it. I also tried indexOf() but its not work
String myString = "20±1";
if(myString.indexOf('±')>-1){
System.out.println("We are in here.........");
}
Use function split()
String myString = "20±1";
String result[] = myString.split("±");
//result[0] = 20
//result[1] = 1
/*Your String*/
String myString = "20±1";
/*If you want to split String you can use String.split("your string regex here")
* and it will create String array without specified string regex with left, right
* side of string or multiple strings depending on occurrence of specified string regex*/
String[] splitted = myString.split("±");
/*Just to validate output*/
System.out.println(Arrays.toString(splitted));
you can use also StringTokenizer
for this problem:
import java.io.*;
import java.util.*;
class happy {
public static void main(String args[])
{
String myString = "20±1";
StringTokenizer st=new StringTokenizer(myString,"±");
String a="";
while(st.hasMoreTokens())
{
a=st.nextToken();
System.out.println(a);
}
}
}