• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

clearing white space

 
Chris Dancy
Ranch Hand
Posts: 136
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
got a quick question. Im trying to clear all the white space from a string. All other characters are ok, just the white space has to go. I've looked online and found nothing useful, I keep getting char cannot be dereferenced errors. here is the code i tried
public String clearWhiteSpace(String si){
char [] temp = si.toCharArray();
String s = "";
for(int i = 0;i < temp.length;i++){
if(!temp[i].equals(' '))
s += temp[i];
}
return s;
}

Im running out of ideas, if anyone can help, let me know.

thanks
Chris Dancy
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Primitives dont have methods. To compare two primitives you use ==.

if(!temp[i] == ' ')
 
Chris Dancy
Ranch Hand
Posts: 136
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ahahaha. Stupid mistake on my part. I should have realized. thanks
 
Henry Wong
author
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also remove spaces from the string, like this...



Henry
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic