Solved

Parse and split a variable into 3 strings

Posted on 2007-04-04
1
230 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Angular JS Route 3 68
SQL Exceptions 3 43
Question! 4 36
HTML - Color not displaying correctly in EMAIL. 6 32
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

806 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