?
Solved

Parse and split a variable into 3 strings

Posted on 2007-04-04
1
Medium Priority
?
236 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month14 days, 22 hours left to enroll

771 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