Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Need to switch 1's and l's in strings.

Posted on 2013-11-11
2
Medium Priority
?
304 Views
Last Modified: 2013-11-11
I have a set of data (text files) with a lot of trouble shooting codes (e.g. lAG51 & lA11B).  My problem is that the data was entered incorrectly and should have been (1AG5l & 1AllB).

I cannot do a straight find and replace as there are too many varying codes and if I do replace 1's with l's and then l's with 1's:

 lAG51  becomes 1AG51 and lA11B becomes 1A11B.

I need a way to switch 1 for l and l for 1.  I was going to use VB.net with regular expressions to find the codes make the corrections.

Any and all help is appreciated.
0
Comment
Question by:NevSoFly
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 22

Accepted Solution

by:
Ivo Stoykov earned 2000 total points
ID: 39638077
one approach is to use additional chars to divide desired replace -
One for 'l' and another for '1':

string pattern = @"^l";
RegexOptions regexOptions = RegexOptions.IgnoreCase | RegexOptions.Compiled;
Regex regex = new Regex(pattern, regexOptions);
string inputData = @"lAG51  becomes 1AG51 ";
string replacement = @"l@";
string result = regex.Replace(inputData, replacement);

Open in new window


string pattern = @"\b1";
RegexOptions regexOptions = RegexOptions.IgnoreCase | RegexOptions.Compiled;
Regex regex = new Regex(pattern, regexOptions);
string inputData = @"lAG51  becomes 1AG51 ";
string replacement = @"1#";
string result = regex.Replace(inputData, replacement);

Open in new window


then just replace 'l@' with '1' and '1#' with 'l'

HTH
Ivo Stoykov
0
 

Author Closing Comment

by:NevSoFly
ID: 39638099
thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question