View previous topic :: View next topic |
Author |
Message |
Madalin Master

Joined: 24 Jun 2005 Posts: 310 Location: Constanta, Romania
|
Posted: Fri Jan 04, 2019 12:46 pm Post subject: Character hiding and showing |
|
|
Evening.
I have a small problem with the following code, meaning that it works 97%
I cannot make it show
'
`
and
?
Code: | 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;
} |
_________________ https://github.com/MadaliNTCL - To chat with me: https://tawk.to/MadaliNTCL |
|
Back to top |
|
 |
caesar Ass Kicker

Joined: 14 Oct 2001 Posts: 3550 Location: Mint Factory
|
Posted: Fri Jan 04, 2019 2:53 pm Post subject: |
|
|
Have you tried string map like:
Code: |
string map [list " " "" "-" "" "," "" "." "" "\(" "" "\)" "" "\'" "" "`" "" "?" "" "*" ""] [split $text]
|
that basically removes the characters leaving everything else? _________________ You may say anything about me, but at least don't misspell my name. xD |
|
Back to top |
|
 |
Madalin Master

Joined: 24 Jun 2005 Posts: 310 Location: Constanta, Romania
|
Posted: Sun Jan 06, 2019 12:50 pm Post subject: |
|
|
I want to show does characters not hide them. _________________ https://github.com/MadaliNTCL - To chat with me: https://tawk.to/MadaliNTCL |
|
Back to top |
|
 |
caesar Ass Kicker

Joined: 14 Oct 2001 Posts: 3550 Location: Mint Factory
|
Posted: Mon Jan 07, 2019 2:08 am Post subject: |
|
|
Ah, sorry, my bad. Loop and lsearch then?
Code: |
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: |
proc hideword word {
set chars {" " "-" "," "." "\(" "\)" "\'" "`" "?" "*"}
foreach c [split $word ""] {
append nw [expr {[lsearch $chars $c] > -1 ? $c : "*"}]
}
return $nw
}
|
_________________ You may say anything about me, but at least don't misspell my name. xD |
|
Back to top |
|
 |
|