Solved

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

Posted on 2013-11-11
2
301 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 500 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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
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…

710 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