| View previous topic :: View next topic |
| Author |
Message |
juanamores Master
Joined: 15 Mar 2015 Posts: 317
|
Posted: Tue Jun 09, 2015 12:02 am Post subject: Remove character of a list |
|
|
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  |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Tue Jun 09, 2015 12:35 am Post subject: |
|
|
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: |
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: |
set cursong [string map [list "Ã" ""] $cursong]
|
_________________ Once the game is over, the king and the pawn go back in the same box. |
|
| Back to top |
|
 |
juanamores Master
Joined: 15 Mar 2015 Posts: 317
|
Posted: Tue Jun 09, 2015 3:04 am Post subject: |
|
|
Perfect! Thanks caesar  _________________ 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  |
|
| Back to top |
|
 |
|