• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to wipe off the whitespace in the String

 
qingwu wang
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everybody!
if there is one function that can wipe off white space in the jdk.if not,can anyone give me some advice?Thanks a lot
 
Wendal Park
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just call the trim() method.
For Example:
String str = "Hello World    ";
str = str.trim() // would give "Hello World"
if you want to remove whitespaces within a string, one way of doing it is:

Wendal
[ June 24, 2003: Message edited by: Wendal Park ]
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello
if you want to replace all there is also a function in 1.4....
replaceAll(String regex, String replacement)
Replaces each substring of this string that matches the given regular expression with the given replacement.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic