| Author |
clearing white space
|
Chris Dancy
Ranch Hand
Joined: Feb 14, 2006
Posts: 136
|
|
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
|
("Anger is not an emotion, its a symptom of fear.")
|
 |
Garrett Rowe
Ranch Hand
Joined: Jan 17, 2006
Posts: 1295
|
|
Primitives dont have methods. To compare two primitives you use ==. if(!temp[i] == ' ')
|
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
|
 |
Chris Dancy
Ranch Hand
Joined: Feb 14, 2006
Posts: 136
|
|
|
ahahaha. Stupid mistake on my part. I should have realized. thanks
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16811
|
|
You can also remove spaces from the string, like this... Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
 |
|
|
subject: clearing white space
|
|
|