| View previous topic :: View next topic |
| Author |
Message |
NewzNZ Halfop

Joined: 05 Mar 2009 Posts: 60
|
Posted: Sun Mar 03, 2019 8:34 pm Post subject: string containing * (asterisk) |
|
|
Hi there
Am trying to detect strings with * (asterisks) in them to do (something)...
Have tied:
| Code: |
if {[string match "{*\*}*" $tt]}
and
if {[string match "*\**" $tt]}
|
...but no luck. Any help would be appreciated!
Cheers |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Mon Mar 04, 2019 1:57 am Post subject: |
|
|
| Code: |
% 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. |
|
| Back to top |
|
 |
NewzNZ Halfop

Joined: 05 Mar 2009 Posts: 60
|
Posted: Mon Mar 04, 2019 2:05 am Post subject: |
|
|
| Thanks for the reply...will give it a go! |
|
| Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
Posted: Mon Mar 04, 2019 11:23 am Post subject: Re: string containing * (asterisk) |
|
|
| NewzNZ wrote: |
...
Am trying to detect strings with * (asterisks) in them to do (something)...
Have tied:
| Code: |
if {[string match "{*\*}*" $tt]}
...
|
|
Playing in partyline, I first did:
| Code: |
.set testtext "bla bla * bla"
|
Next:
| Code: |
<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: |
<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 ! |
|
| Back to top |
|
 |
|