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.
Madalin
Master
Posts: 310 Joined: Fri Jun 24, 2005 11:36 am
Location: Constanta, Romania
Contact:
Post
by Madalin » Fri Jan 04, 2019 12:46 pm
Evening.
I have a small problem with the following code, meaning that it works 97%
I cannot make it show
'
`
and
?
Code: Select all
proc hideword {word} {
set newword "";
foreach letter [split $word {}] {
if {$letter ne " " && $letter ne "-" && $letter ne "," && $letter ne "." && $letter ne "(" && $letter ne ")" && $letter ne "'" && $letter ne "`" && $letter ne "?"} {set letter "*";}
append newword $letter;
}
return $newword;
}
caesar
Mint Rubber
Posts: 3778 Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory
Post
by caesar » Fri Jan 04, 2019 2:53 pm
Have you tried string map like:
Code: Select all
string map [list " " "" "-" "" "," "" "." "" "\(" "" "\)" "" "\'" "" "`" "" "?" "" "*" ""] [split $text]
that basically removes the characters leaving everything else?
Once the game is over, the king and the pawn go back in the same box.
Madalin
Master
Posts: 310 Joined: Fri Jun 24, 2005 11:36 am
Location: Constanta, Romania
Contact:
Post
by Madalin » Sun Jan 06, 2019 12:50 pm
I want to show does characters not hide them.
caesar
Mint Rubber
Posts: 3778 Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory
Post
by caesar » Mon Jan 07, 2019 2:08 am
Ah, sorry, my bad. Loop and
lsearch then?
Code: Select all
proc hideword word {
set chars {" " "-" "," "." "\(" "\)" "\'" "`" "?" "*"}
foreach c [split $word ""] {
if {[lsearch $chars $c] > -1} {
append nw $c
} else {
append nw "*"
}
}
return $nw
}
and a "compact" version:
Code: Select all
proc hideword word {
set chars {" " "-" "," "." "\(" "\)" "\'" "`" "?" "*"}
foreach c [split $word ""] {
append nw [expr {[lsearch $chars $c] > -1 ? $c : "*"}]
}
return $nw
}
Once the game is over, the king and the pawn go back in the same box.