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.

Removing characters from a string with regsub

Old posts that have not been replied to for several years.
Locked
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Removing characters from a string with regsub

Post by awyeah »

Hi,

Suppose if I want to remove spaces from a string
would this be the command?

The $arg string variable will remove spaces from
the string and form the new $text variable with
the spaces removed.

Is this correct?

regsub -all " " $arg "" text


If so, can the same be done for alphabets
and numbers,

Like using \[A-Z\] to remove all upper case chars
and \[0-9\] to remove all numbers from the string.

Something like:

regsub -all "\[A-Z\]" $arg "" text
regsub -all "\[0-9\]" $arg "" text
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
d
dollar
Op
Posts: 178
Joined: Tue Oct 28, 2003 3:47 pm
Location: Netherlands

Post by dollar »

How about trying? :P

Code: Select all

% set arg "blah blah blah"
blah blah blah
% regsub -all { } $arg {} text
2
% puts $text
blahblahblah
% set arg "Blah bLah blAh"
Blah bLah blAh
% regsub -all {[A-Z]} $arg {} text
3
% puts $text
lah bah blh
% set arg "bl4h b1ah bla8"
bl4h b1ah bla8
% regsub -all {[0-9]} $arg {} text
3
% puts $text
blh bah bla
dollar (or something similar) at:
#eggdrop / #tcl - undernet
#egghelp / #tcl / #eggtcl - efnet
#eggdrop.support / #tcl - quakenet
#eggdrop - ircnet
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

Thanks, that's also a good idea.
Both work anyhow.
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
Locked