Re: Regex.Replace...
Gary Harpin <[email protected]> Fri, 12 Oct 2007 11:47:27 +0100
| Newsgroups | gmane.comp.windows.devel.dotnet.cx |
|---|---|
| Message-ID | <[email protected]> |
Thanks, that did the trick! I will have to read up more on Regex. 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 > -----Original Message----- > From: Discussion relating to the specifics of the C# and Managed C++ > languages [mailto:[email protected]] On Behalf Of Efran > Cobisi > Sent: Friday, October 12, 2007 11:28 AM > To: [email protected] > Subject: Re: [DOTNET-CX] Regex.Replace... >=20 > Hi Gary, >=20 > You have to edit your expression in order to do exactly what you are > looking for; after replacing any ones and zeroes as you have done, you > could easily perform a regex replace as the following one: >=20 > // ... > cleankey =3D Regex.Replace(cleankey, "[^a-zA-Z2-7]", String.Empty); > // ... >=20 > HTH >=20 > -- > Efran Cobisi > http://www.cobisi.com >=20 > Gary Harpin wrote: > > Hello all, > > > > 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"); > > 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 '-'. > > > > I don't understand regex that well and could do with a hand. > > > > Thank you. > > > > Regards, > > Gary Harpin > > > > ________________________________ > > > > "...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] > > > > > > = =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(r) http://www.develop.com > > > > View archives and manage your subscription(s) at > http://discuss.develop.com > > >=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(r) http://www.develop.com >=20 > View archives and manage your subscription(s) at > http://discuss.develop.com =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