Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Parse and split a variable into 3 strings

Posted on 2007-04-04
1
Medium Priority
?
237 Views
Last Modified: 2010-04-15
I have a string like this format....    2:30 PM and I want to parse into 3 different variables. So to the left of the colon : is one variable, then the next 2 digits is another variable and the last 2 is the final variable. What is the best way to parse this?
0
Comment
Question by:chicabow
[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
1 Comment
 
LVL 9

Accepted Solution

by:
WinterMuteUK earned 200 total points
ID: 18850413
Hi Chicabow,

One way to do this is like this:

            string str = "2:30 PM";
            string[] split = str.Split(": ".ToCharArray());
            for(int i = 0; i < split.Length; i++)
               Console.WriteLine(i + " --> " + split[i]);

in this case,
  split[0] = 2
  split[1] = 30
  split[2] = PM

You could assign these to your own vars however you want.

Cheers

Wint
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

610 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