Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2013-11-11
2
Medium Priority
?
307 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
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Do you hate spam? I do, and I am willing to bet you do as well. I often wonder, though, "if people hate spam so much, why do they still post their email addresses on the web?" I'm not talking about a plain-text posting here. I am referring to the fa…
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…
Suggested Courses

772 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