I have a string like this:
mysz = \"name=john age=13 year=2001\";
I want to remove the whitespaces in the string. I tried trim()
You can also take a look at the below Java code. Following codes does not use any "built-in" methods.
/**
* Remove all characters from an alphanumeric string.
*/
public class RemoveCharFromAlphanumerics {
public static void main(String[] args) {
String inp = "01239Debashish123Pattn456aik";
char[] out = inp.toCharArray();
int totint=0;
for (int i = 0; i < out.length; i++) {
System.out.println(out[i] + " : " + (int) out[i]);
if ((int) out[i] >= 65 && (int) out[i] <= 122) {
out[i] = ' ';
}
else {
totint+=1;
}
}
System.out.println(String.valueOf(out));
System.out.println(String.valueOf("Length: "+ out.length));
for (int c=0; c= 48 && (int) out[d] <=57 ) {
System.out.println(out[d]);
whitespace[t]= out[d];
t+=1;
}
}
System.out.println("**********");
System.out.println("**********");
System.out.println("The String is: " + String.valueOf(whitespace));
}
}
Input:
String inp = "01239Debashish123Pattn456aik";
Output:
The String is: 01239123456