Results 1 to 8 of 8
Thread: deleting spaces !!
- 03-30-2011, 11:13 AM #1
Member
- Join Date
- Mar 2011
- Posts
- 7
- Rep Power
- 0
- 03-30-2011, 11:25 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
What is the error you are getting?
- 03-30-2011, 12:20 PM #3
Member
- Join Date
- Mar 2011
- Posts
- 7
- Rep Power
- 0
The left-hand side of an assignment must be a variable
- 03-30-2011, 01:03 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
There you go then.
And, to save you some trouble looking for a setCharAt() method, Strings are immutable...that is they cannot be changed.
StringBuilder might help there.
- 03-30-2011, 02:28 PM #5
Member
- Join Date
- Mar 2011
- Posts
- 7
- Rep Power
- 0
thanks a lot Tolls :)
the code is right now ;)
here is my code :
public class main2 {
public static void main(String[] args) {
// delete extra spaces
StringBuffer ch=new StringBuffer(100);
int i =0;
ch.append(" g d ");
if (ch.charAt( 0)==' ')
ch.deleteCharAt(0);
if(ch.charAt(ch.length()-1)==' ')
ch.deleteCharAt(ch.length()-1);
while (i<ch.length()-1)
{
if ((ch.charAt(i)==' ')&&(ch.charAt(i+1)==' '))
{
ch.deleteCharAt(i+1);
}
else
i++;
}
System.out.println(ch);
}
}
- 03-30-2011, 02:34 PM #6
You can use RegExp.
Java Code:String text = "Hello world"; text = text.replaceAll("\\s+", "");Skype: petrarsentev
http://TrackStudio.com
- 03-30-2011, 02:43 PM #7
Member
- Join Date
- Mar 2011
- Posts
- 7
- Rep Power
- 0
text = text.replaceAll("\\s+", "");
\\s+ -->what do you mean Petr ??
- 03-30-2011, 03:11 PM #8
Similar Threads
-
Extra spaces in JLabel...Please help..
By sohamde in forum New To JavaReplies: 6Last Post: 12-06-2010, 03:53 AM -
Replace a cell with Spaces
By Shyamz1 in forum New To JavaReplies: 11Last Post: 11-07-2010, 02:37 PM -
problem with spaces in
By olli_m in forum IntelliJ IDEAReplies: 0Last Post: 11-24-2009, 05:55 PM -
How do i add spaces ~(very simple)
By soc86 in forum New To JavaReplies: 3Last Post: 11-02-2008, 02:01 AM -
Load URL that contains spaces?
By barkster in forum Java AppletsReplies: 0Last Post: 01-30-2008, 09:40 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks