|
-
Dec 14th, 2009, 09:54 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Simple code
I have text for example:
11.12.2009 or 7.8.2004 and how to get three variables, a, b, c
a = 7
b = 8
c = 2004
Thanks!
-
Dec 14th, 2009, 10:00 AM
#2
Re: Simple code
Well, those sure look like dates, which offers up a couple methods. Since they are strings now, one thing you can do is to get the pieces directly with SubString, but that would get awkward since the dots can move around depending on whether the day and month are single or double digit. The better way to do this would be to convert to date using CDate (if you can be certain that they will always be dates, and Date.TryParse otherwise). You can then use the Month, Day, and Year properties to get those pieces from the date.
My usual boring signature: Nothing
 
-
Dec 14th, 2009, 10:36 AM
#3
Thread Starter
Addicted Member
Re: Simple code
I don't understand. That's not a date (just look like date), this can be some other string (98.72.2941), code?
-
Dec 14th, 2009, 10:42 AM
#4
-
Dec 14th, 2009, 11:50 AM
#5
Thread Starter
Addicted Member
Re: Simple code
Does somebody have code for this I ask. I know when I have two elements
split
string(0)
string(1)
and now with point???
-
Dec 14th, 2009, 11:52 AM
#6
Member
Re: Simple code
Dim a As Integer = ""
Dim b As Integer = ""
Dim c As Integer = ""
Would this work? :S
VB 2008 Beginner
I'll Try And Help As Much As I Can
-
Dec 14th, 2009, 11:58 AM
#7
Fanatic Member
Re: Simple code
Code:
Dim test as string = "78.95.9646"
Dim splitString() as String
splitString()= test.split(".")
' At this point we have 3 strings in an array
Dim a, b, c as integer
a = CInt(splitstring(0))
b = CInt(splitstring(1))
c = CInt(splitstring(2))
If debugging is the process of removing bugs, then programming must be the process of putting them in.
-
Dec 14th, 2009, 12:04 PM
#8
Thread Starter
Addicted Member
Re: Simple code
Thank you Megalith!
-
Dec 14th, 2009, 03:24 PM
#9
Re: Simple code
 Originally Posted by Megalith
Code:
Dim test as string = "78.95.9646"
Dim splitString() as String
splitString()= test.split(".")
' At this point we have 3 strings in an array
Dim a, b, c as integer
a = CInt(splitstring(0))
b = CInt(splitstring(1))
c = CInt(splitstring(2))
This only works so long as the string contains only numbers separated by periods.
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
|