|
-
Feb 25th, 2010, 02:38 PM
#1
Thread Starter
Addicted Member
[RESOLVED] Strings and numbers
Hello everybody!
I'm interested in: how to split for example this record:
ab ab ab 22.04.2009
So, I want to have two variables.
A: ab ab ab
B: 22.04.2009
So, first string will always be a one word (or more), and the another string will always be number (always as date)
Thanks!
-
Feb 25th, 2010, 02:59 PM
#2
Hyperactive Member
Re: Strings and numbers
Well first I need to know what if any assumptions there are. Meaning, does the date portion of the string always exist in DD/MM/YYYY format? Does the date always occur at the end of the string? That way you know that the date portion of the string is always 10 characters long(including the periods). Using this info you can subtract that value from the length of the string and use that to determine where the text and date portion of the string begins. Here is an example...
Code:
Dim Record as String = "ab ab ab 22.04.2009"
Dim WordPartOfRecord as String
Dim DatePartOfRecord as DateTime
WordPartOfRecord = Record.Substring(0, (Record.Length - 10))
DatePartOfRecord = Convert.ToDateTime(Record.SubString(WordPartOfRecord.Length+1))
-
Feb 25th, 2010, 03:05 PM
#3
Thread Starter
Addicted Member
Re: Strings and numbers
Thank you!
-
Feb 25th, 2010, 03:11 PM
#4
Re: [RESOLVED] Strings and numbers
As long as all your dates having the same format dd.MM.yyyy then that code will work. If any of the dates is in short format, for example 22.4.2009 or 1.2.2010 instead of 22.04.2009 or 01.02.2010 then that code will not work.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Feb 25th, 2010, 04:08 PM
#5
Hyperactive Member
Re: [RESOLVED] Strings and numbers
 Originally Posted by stanav
As long as all your dates having the same format dd.MM.yyyy then that code will work. If any of the dates is in short format, for example 22.4.2009 or 1.2.2010 instead of 22.04.2009 or 01.02.2010 then that code will not work.
Thats right. It all depends on the data and the assumptions you can make and he would know that.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|