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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with string map replacing numbers

Status
Not open for further replies.

kcrist84

Programmer
Jul 14, 2008
6
0
0
US
I need some help with a string map command. I am trying to replace special characters with a {}. For example if the number was 12456-21 i want 1245621, 1245a47 to 124547. I can get the special characters out, but how do i set it up to get rid of the letters. I have tried A-Z, a-z, A-z, chars with no luck. I am sure their is a way to do it so i dont have a {} b {} c {}...etc. All way through alphabet. So i basically want to take out anything non-numeric. Below is my current code, any help or direction would be appreciated.

set PolicyNum [string map -nocase {- {} ? {} . {} ' {} @ {} char {}}
 
Hi

Why not use [tt]regsub[/tt] ?
Code:
[b]set[/b] dirtyPolicyNum [green][i]"12456-21"[/i][/green]

[b]regsub[/b] [teal]-[/teal]all [teal]{[/teal][teal]\[/teal]D[teal]}[/teal] [navy]$dirtyPolicyNum[/navy] [teal]{}[/teal] cleanPolicyNum

[b]puts[/b] [navy]$cleanPolicyNum[/navy] [gray]# outputs 1245621[/gray]

Feherke.
 
string map will work with a map of, say {- ""}:
Code:
% string map {- ""} abc-123
abc123

_________________
Bob Rashkin
 
Sorry. I just realized what you were asking. I think you'd be better advised to go with regsub.

_________________
Bob Rashkin
 
Thanks all for your replies and bear with me...but what does the {\D} mean? Does it mean everything but numbers?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top