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

x
?
Solved

parsing a string with automated tools

Posted on 2006-10-21
4
Medium Priority
?
271 Views
Last Modified: 2010-04-16
Greetings,

I have a string to parse which might fit either of these two models.

 CA LOS ANGELES  AFTON PL          6100-6299    8131        20    90028  
                            ALCYONA DR      2100-2399    8131        11    90068  

I need to easily parse this to fill:

string state;
string city;
string street;

but I want to design the approach to be a bit flexible in the event I need to change it.
So I think using automated tools would be the preferred method.

Can anybody suggest how to do this?

Bob
What's the easiest way


0
Comment
Question by:ba272
[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
4 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 17780916
Are the "fields" in the string fixed width?
0
 

Author Comment

by:ba272
ID: 17780924
yes
0
 
LVL 7

Expert Comment

by:Mohamed Zedan
ID: 17783242
could you give the fields description ....
      field1           field2
|---5chars---||--2Chars--|

etc... this would ease the job :)
0
 
LVL 64

Accepted Solution

by:
Fernando Soto earned 2000 total points
ID: 17784024
Hi Bob;

Below is sample code to do what you want.

            string[] TestData = {
                "CA LOS ANGELES  AFTON PL          6100-6299    8131        20    90028",
                "                ALCYONA DR        2100-2399    8131        11    90068"
            };
            string State;
            string City;
            string Street;

            // In this code sample I am assuming the following
            //     State is in position index  0-1
            //     City is in position index   3-14
            //     Street is in position index 16-32
            // The first and second parameter of SubString will need to be adjusted
            // to meet the acual field start index and length
            foreach (string data in TestData)
            {
                // Parse the data
                State = data.Substring(0, 2).Trim();
                if (State.Length == 0) State = "<Empty State Field>";
                City = data.Substring(3, 12).Trim();
                if (City.Length == 0) City = "<Empty City Field>";
                Street = data.Substring(16, 17).Trim();
                if (Street.Length == 0) Street = "<Empty Street Field>";
                // Use the parsed data as needed
                MessageBox.Show(State + "\n" + City + "\n" + Street);
            }


Fernando
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

722 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