Solved

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

Posted on 2013-11-11
2
296 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
Comment Utility
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
Comment Utility
thanks
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

728 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now