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.

Remove character of a list

Help for those learning Tcl or writing their own scripts.
Post Reply
j
juanamores
Master
Posts: 317
Joined: Sun Mar 15, 2015 9:59 am

Remove character of a list

Post by juanamores »

I would like the list that is stored in the cursong variable, if present the character "Ã" is removed.
But I do not want to replace the space or another character, simply remove it.
Example: if the cursong variable returns: We are the wÃorld
To return: We are the world
If you do not understand my ideas is because I can not think in English, I help me with Google Translate. I only speak Spanish. Bear with me. Thanks :)
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

A combination of lsearch to find it's position and lremove to remove the element in said position will do what you asked for.

Code: Select all

set pos [lsearch $cursong "Ã"]
if {$pos != -1} {
	set cursong [lreplace $cursong $pos $pos]
}
But this will replace only the first match it will find, meaning if you got two à characters then only the first one will be replaced. To remove all the occurrences of this character you could use string map instead:

Code: Select all

set cursong [string map [list "Ã" ""] $cursong]
Once the game is over, the king and the pawn go back in the same box.
j
juanamores
Master
Posts: 317
Joined: Sun Mar 15, 2015 9:59 am

Post by juanamores »

Perfect! Thanks caesar :D
If you do not understand my ideas is because I can not think in English, I help me with Google Translate. I only speak Spanish. Bear with me. Thanks :)
Post Reply