Hello All, I want to remove white spaces from a string i know that trim() is used to remove white spaces but from both ends of the string but how if those white spaces inside the String . i wish anyone can help thanks in advancd
Hesham Katon<br />SCJP 1.2<br />SCWCD 1.4<br />Better to light a candle than to curse the darkness
Several ways, but no real one-shot solution. 1) use a regular expression to filter the string, returning everything but whitespace 2) go through the string character by character, building a new string based on the old one minus the spaces 3) use a StringTokenizer, tokenizing on spaces, and create a new string from the resulting chunks. I guess the first is fastest to execute, the 2nd faster to code (unless you're a RegExp guru).
Joined: Oct 12, 2000
Dirk, any timeframe on parts 3 and 4 of your series on Regular Expressions? Makes for interesting reading for those who haven't been bitten by them a lot (like me) coming from places that are not Perl
Joined: Dec 10, 2001
[Continuing a light thread hijack...] It's been almost a year-and-a-half since I wrote those four articles, of which only the first two have made an appearance. I still feel stuck on the first two as the feedback I've received from beginners was simply of the nature "This is hard!" which isn't what I was striving for. (Developers with previous regex experience have seemed to appreciate them, so far.) So, I've been meaning to spend some time figuring out improving them for the beginner to regular expressions. [/Continuing a light thread hijack...]