Solved

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

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.net and sql server 4 45
How do sunrise and sunset times change with altitude 14 35
Looping through datagridview and dataset ? 6 24
Name Space error VS2015 1 22
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 …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
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…

840 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