Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Character Substitution

Status
Not open for further replies.

dcomit

Technical User
Jun 20, 2001
115
GB
Hello,

I’m new to tcl and would like some help. I need to replace ampersands with ‘AND’ in a field. There are four scenarios depending upon what precedes and follows the ampersand, eg:

Space ampersand space (MR & MRS to MR AND MRS)
Anything ampersand anything (LORD&LADY to LORD AND LADY)
Space ampersand anything (GOAT &COMPASSES to GOAT AND COMPASSES)
Anything ampersand space (MR& MS to MR AND MS)

Any help would be appreciated.

Dave
 
First, I would replace the "&" with " AND " using "string map":

set <new string> [string map {& " AND "} $<old string>]

(note, <new string> and <old string> can be the same.)

Then I would get rid of double spaces, also with "string map":

set <new string> [string map {" " " "} $<old string>]


Bob Rashkin
rrashkin@csc.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top