Solved

Parse and split a variable into 3 strings

Posted on 2007-04-04
1
225 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
1 Comment
 
LVL 9

Accepted Solution

by:
WinterMuteUK earned 50 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 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

16 Experts available now in Live!

Get 1:1 Help Now