Mitch0492
Mitch0492

Reputation: 5

How to split a String using multiple delimeters

I'm using a very particular program that doesn't have many pre loaded functions on it. I would like to split a Date and time into individual variables. 6 variables to be exact

I get the date and time like this 5/28/2014 15:34:40 so I have 3 characters "/" " " and ":" separating the 6 variables I want, but I can only get one to work at a time. I have tried many other ways but the x.Split() is the only syntax that this program seems to like (PARCView).

Dim x as String = "5/28/2014 15:34:40"
Dim y as String() = x.Split(New Char() {":"c})

So how can I add all three at once or use consecutive steps to store each number as a unique variable?

Upvotes: 0

Views: 3048

Answers (2)

tinstaafl
tinstaafl

Reputation: 6958

Another option is to parse it as a datetime object which will contain all the parts as properties:

Dim teststr = "5/28/2014 15:34:40"
Dim dt = DateTime.Parse(teststr)

Upvotes: 1

Mark Hall
Mark Hall

Reputation: 54562

You actually have the Char Array that you need, though it only has one delineator... just fill it with the other delineators and it will split it for you.

Dim y As String() = x.Split(New Char() {":"c, "/"c, " "c})

example:

enter image description here

Upvotes: 2

Related Questions