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.
Help for those learning Tcl or writing their own scripts.
-
NewzNZ
- Halfop
- Posts: 68
- Joined: Thu Mar 05, 2009 5:15 am
-
Contact:
Post
by NewzNZ »
Hi there
Am trying to detect strings with * (asterisks) in them to do (something)...
Have tied:
Code: Select all
if {[string match "{*\*}*" $tt]}
and
if {[string match "*\**" $tt]}
...but no luck. Any help would be appreciated!
Cheers
-
caesar
- Mint Rubber
- Posts: 3778
- Joined: Sun Oct 14, 2001 8:00 pm
- Location: Mint Factory
Post
by caesar »
Code: Select all
% set text "* bla bla * bla"
* foo
% string first * $text
0
% set text "bla bla * bla"
bla bla * bla
% string first * $text
8
as you can see it returns the position of first match.
Once the game is over, the king and the pawn go back in the same box.
-
NewzNZ
- Halfop
- Posts: 68
- Joined: Thu Mar 05, 2009 5:15 am
-
Contact:
Post
by NewzNZ »
Thanks for the reply...will give it a go!
-
willyw
- Revered One
- Posts: 1205
- Joined: Thu Jan 15, 2009 12:55 am
Post
by willyw »
NewzNZ wrote:
...
Am trying to detect strings with * (asterisks) in them to do (something)...
Have tied:
Code: Select all
if {[string match "{*\*}*" $tt]}
...
Playing in partyline, I first did:
Next:
Code: Select all
<myhandle> .tcl string match {*\**} $testtext
<botnick> Tcl: 1
Compared to yours, all I did was move the last asterisk to be inside the curly braces.
For the heck of it, I then played with it some more:
Code: Select all
<myhandle> .tcl string match {*\* *} $testtext
<botnick> Tcl: 1
<myhandle> .tcl string match {* \* *} $testtext
<botnick> Tcl: 1
<myhandle> .tcl string match {* \* *} $testtext
<botnick> Tcl: 0
<myhandle> .tcl string match {* \* *} $testtext
<botnick> Tcl: 1
I hope this helps.
For a fun (and popular) Trivia game, visit us at: irc.librairc.net #science-fiction . Over 300K Q & A to play in BogusTrivia !