String output = new String(encryptText);
output = output.replaceAll("\\s", "");
return output;
replaceAll("\\s", ""); doesn't work
String output = new String(encryptText);
output = output.replaceAll("\\s", "");
return output;
replaceAll("\\s", ""); doesn't work
String output = new String(encryptText);
output = output.replaceAll(" ", "");
return output;
Use String.replaceAll(" ","") or if you want to do it yourself without a lib call, use this.
String encryptedString = "The quick brown fox ";
char[] charArray = encryptedString.toCharArray();
char [] copy = new char[charArray.length];
int counter = 0;
for (char c : charArray)
{
if(c != ' ')
{
copy[counter] = c;
counter++;
}
}
char[] result = Arrays.copyOf(copy, counter);
System.out.println(new String(result));
Your code works fine for me, see here
Anyway you can use the StringUtils.trimAllWhitespace from the spring framework:
output = StringUtils.trimAllWhitespace(output);