i have an input string , and i want to remove All char except special character(Hex Character) ! like this :
String SpecialChar = "0123456789ABCDEF" ; // Hex Char
String input = "abdf%$%23%&373D^!Bfg(g)*a" ;
i want to have below output , but i get wrong value ...
String output = "abdf23373DBfgga" ;
i write below method but it return wrong value :
private String EliminateExtra(String str) {
String temp = str.toUpperCase();
for (int i = 0 ; i < temp.length() ; i++) {
char c = temp.charAt(i);
if(!isHexNum(c)) {
temp = temp.replaceAll(String.valueOf(c) , "");
}
}
return temp ;
}
private Boolean isHexNum(char c) {
char[] charArray = "0123456789ABCDEF".toCharArray();
for(int y=0 ; y<charArray.length ; y++) {
if(charArray[y]==c) {
return true ;
}
}
return false ;
}
and call it like :
String Data = "aaaDffagDDSGw!$!@$3513rX12433r1ADSfX&)&*)%(%8u4w" ;
TextView tv = (TextView) findViewById(R.id.regex_textView1) ;
tv.setText("Original:" + "\n" + Data.toUpperCase() + "\n" + "Result: " + "\n" + EliminateExtra(Data));