Tcl/Tk: Substituir strings

Para manipular Strings em Tcl, utilizamos o comando string.

Se precisar substituir ponto por vírgula:

set valor { 10.00 }
puts [string map -nocase { . , }  $valor]

# Retorna: 10,00

Podemos substituir várias cadeias de caracteres:

set texto "Este é um texto de teste de substituição"
puts [string map -nocase { e E s S b B } $texto]

# Retorna: EStE é um tExto dE tEStE dE SuBStituição

Naturalmente, podemos substituir palavras:

set texto "Este é um texto de teste de substituição"
puts [string map -nocase { teste TESTE um {o segundo} } $texto]

# Retorna: Este é o segundo texto de TESTE de substituição
This entry was posted in Tcl-Tk and tagged , , , . Bookmark the permalink.