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!

code search and replace..

Status
Not open for further replies.

snowingnow

Programmer
Jun 1, 2006
32
CA
how can i do a search and replacement,
that say, the province code replace, if the value is ontario then replace with ON, Alberta, replace with AB ... So on... Thanks
 
This should get you started ... it works fine! You make need to tweak for your application, especially if you want to not search on exact providence, etc.

# Expand this array list for all providences
set a_pr(Ontario) "ON"
set a_pr(Alberta) "AB"

proc FandR {sent} {
global a_pr
foreach prov [array names a_pr] {
set si [lsearch -exact $sent $prov]
if {$si != -1} {
set sent [lreplace $sent $si $si $a_pr($prov)]
}
}
return $sent
}

set input1 "I live in Ontario Alberta"

set newline [FandR $input1]
puts $newline
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top