This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.
For more information, see this announcement post . Click the X in the top right-corner of this box to dismiss this message.
Old posts that have not been replied to for several years.
s
skirmis
Post
by skirmis » Thu Jan 23, 2003 6:27 pm
Hello,
Can someone help with this, I need to remove multiple spaces from string. For example I have "hello I am bot". I need to get this format "hello I am bot". How can I replace two or more spaces into one ?
Thanks for advices.
SkIRmiS
ppslim
Revered One
Posts: 3914 Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England
Post
by ppslim » Thu Jan 23, 2003 7:36 pm
The forum, will not display spaces correctly, unless you place them in a "CODE" block.
However, this should remove the spaces.
Code: Select all
proc remspaces {string} {
set a [list]
foreach b [split $string] {
if {$b == ""} { continue }
lappend a $b
}
return [join $b]
}
Use like code
Code: Select all
set mytext "hello with multiple spaces"
set mytext [remspaces $mytext]
s
skirmis
Post
by skirmis » Thu Jan 23, 2003 8:23 pm
Hi,
Something is wrong here, because I got only the last word of string.
-----------------------------------
proc remspaces {string} {
set a
foreach b [split $string] {
if {$b == ""} { continue }
lappend a $b
}
return [join $b]
}
set dat ""
set dat "here is a test"
set dat [remspaces $dat]
putnotc $nick $dat
-----------------------------------
And result is : test
Thanks in advice
[/code]
ppslim
Revered One
Posts: 3914 Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England
Post
by ppslim » Thu Jan 23, 2003 8:36 pm
My fault.
In that code, change the "return [join $b]" to "return [join $a]"
strikelight
Owner
Posts: 708 Joined: Mon Oct 07, 2002 10:39 am
Contact:
Post
by strikelight » Thu Jan 23, 2003 10:44 pm
I myself would just use something like:
Code: Select all
regsub -all { [^ ]*} $text "" text
ppslim
Revered One
Posts: 3914 Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England
Post
by ppslim » Fri Jan 24, 2003 5:49 am
I hate regular expressions.
I fully well understand there power, but I simply can't understand how to create/format them properly.
Most of the reasons why I do things a slightly hard, yet still simple way.
s
skirmis
Post
by skirmis » Fri Jan 24, 2003 7:46 am
Thanks to all who helped me
everything is working fine now !
Bye
SkIRmiS