egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

question & exclaimation marks

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
NewzNZ
Halfop


Joined: 05 Mar 2009
Posts: 60

PostPosted: Sat Aug 22, 2020 11:07 pm    Post subject: question & exclaimation marks Reply with quote

Hi there

Am just trying to filter question marks or exclaimation marks in a string...just wondering if something like this is the right way about it:
Code:

   if {[string match {*\?*} $var] || [string match {*\!*} $var]} {
         do some stuff here etc
}

Thanks in advance for any help!
Back to top
View user's profile Send private message Visit poster's website
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Sun Aug 23, 2020 3:54 am    Post subject: Reply with quote

What do you mean by filtering? If you mean to see if the string has any of the two then you got two options: string index or regexp.

string first
Code:

% set text "something ! in here"
something ! in here
% string first "!" $text
10

notice that this returns the position of the needle in the haystack, so you need to do something like:
Code:

if {[string first "!" $text] > -1 || [string first "?" $text] > -1} {
# do something
}

regexp:
Code:

% regexp -- {\!|\?} $text
1

notice that this one returns 0/1 (false or true) if any of the two is in there.

If you meant to replace/remove them from the string then you need string map like this:
Code:

% string map {"!" ""} $text
something  in here
% set text "something ? in here"
something ? in here
% string map {"?" ""} $text
something  in here


Edit: Fixed a typo.
_________________
Once the game is over, the king and the pawn go back in the same box.


Last edited by caesar on Mon Aug 24, 2020 12:38 am; edited 1 time in total
Back to top
View user's profile Send private message
NewzNZ
Halfop


Joined: 05 Mar 2009
Posts: 60

PostPosted: Sun Aug 23, 2020 4:59 pm    Post subject: Reply with quote

Hi - that's great thank you for the suggestions - will try those options...

Thank you again!
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber