Regex.Replace...
Gary Harpin <[email protected]> Fri, 12 Oct 2007 11:23:40 +0100
| Newsgroups | gmane.comp.windows.devel.dotnet.cx |
|---|---|
| Message-ID | <[email protected]> |
Hello all,=20
I am trying to use Regex.Replace() to clean a string before working on
it.
The incoming string can be of the form " 5E1Y - UMCF - PZNG - RPR4 -
H4KF - 6ICJ - HQ " or "5E1Y:UMCF:PZNG" or ... and I need to replace any
ones and zeros with Is and Os and the strip it of everything that is not
A-Z or 2-7. "5EIYUMCFPZNGRPR4H4KF6ICJHQ"
So far I do the following:
...
cleankey =3D cleankey.Replace("1", "I").Replace("O", "0"); =20
cleankey =3D Regex.Replace(cleankey, @"-([A-Z2-7])*", "");
...
The data will come from multiple sources (database, files, user input)
so need to handle different encodings, the above code fails on the first
stample because the last '-'. =20
I don't understand regex that well and could do with a hand.
Thank you.
Regards,
Gary Harpin
=20
________________________________
"...a computer is a stupid machine with the ability to do incredibly
smart things, while computer programmers are smart people with the
ability to do incredibly stupid things. They are, in short, a perfect
match.." Bill Bryson
[No Disclaimer]
=20
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
This list is hosted by DevelopMentor=AE http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com