Can someone help me how to skip word like I'll . it's , she's ... in $text? thanks
while {[regexp -indices -start $pos {[^[:punct:]\s]+} $text match]} {
lappend words $match
lassign $match -> pos
incr pos
}
Code: Select all
<speechles> .tcl set a "I'll . it's , she's ..."
<bot> Tcl: I'll . it's , she's ...
<speechles> .tcl set b [string map {"." "" "?" "" "," ""} $a]
<bot> Tcl: I'll it's she's
<speechles> .tcl set c [join [split $b]]
<bot> Tcl: I'll it's she's
garung wrote:speechless, it's tnot that, i mean skip these words(he's she's it's) so that they dont replace them with asterisks
Code: Select all
<speechles> .tcl set a [asterize "this, is a word. this is a question?"]
<bot> Tcl: ****, ** * ****. **** ** * ********?
<speechles> .tcl set a [asterize "he's got this. she's got that. you've got those."]
<bot> Tcl: **'* *** ****. ***'* *** ****. ***'** *** *****.
Code: Select all
proc asterize {text} {
set asterisktext ""
foreach word [split $text] {
set asteriskword ""
foreach char [split $word ""] {
if {[string match *$char* "`~!@#$%^&()\[\]\{\}:;'"<>\?,."]} {
append asteriskword $char
} else {
append asteriskword "*"
}
}
append asterisktext "$asteriskword "
}
return [string trim $asterisktext]
}