Splitting a String 
Author Message
 Splitting a String

Hello,

I was wondering how I could split this string into multiple variables. I
want to split it in two ways:

1. At each comma
2. Further split the date into three variables

Here is the string:  DARHS,0102,1/2/2002

I want to split it like this:
strCode = DARHS (this is always five letters)
strID = 0102 (this can be any amount of numbers)
strYear = 2002
strMonth = 1
strDate = 2

Also, is it possible to make the month and date two digits (ex: month = 01,
date = 02) instead of just one?

I appreciate the help.

Chris



Wed, 01 Jun 2005 00:08:44 GMT  
 Splitting a String
use the split() function to convert your string to an array, then affect
each member of the array to your variables.
resplit your date with / as a delimitor.
then use right("00"+string,2) to get the leading zero

Quote:
> Hello,

> I was wondering how I could split this string into multiple variables. I
> want to split it in two ways:

> 1. At each comma
> 2. Further split the date into three variables

> Here is the string:  DARHS,0102,1/2/2002

> I want to split it like this:
> strCode = DARHS (this is always five letters)
> strID = 0102 (this can be any amount of numbers)
> strYear = 2002
> strMonth = 1
> strDate = 2

> Also, is it possible to make the month and date two digits (ex: month =
01,
> date = 02) instead of just one?

> I appreciate the help.

> Chris



Wed, 01 Jun 2005 00:16:17 GMT  
 Splitting a String
Thanks for the help. The only problem is that the "right("00"+string,2) "
doesnt work. Any ideas? Thanks,

Chris


Quote:
> use the split() function to convert your string to an array, then affect
> each member of the array to your variables.
> resplit your date with / as a delimitor.
> then use right("00"+string,2) to get the leading zero


> > Hello,

> > I was wondering how I could split this string into multiple variables. I
> > want to split it in two ways:

> > 1. At each comma
> > 2. Further split the date into three variables

> > Here is the string:  DARHS,0102,1/2/2002

> > I want to split it like this:
> > strCode = DARHS (this is always five letters)
> > strID = 0102 (this can be any amount of numbers)
> > strYear = 2002
> > strMonth = 1
> > strDate = 2

> > Also, is it possible to make the month and date two digits (ex: month =
> 01,
> > date = 02) instead of just one?

> > I appreciate the help.

> > Chris



Wed, 01 Jun 2005 01:17:44 GMT  
 Splitting a String
Chris Guimbellot wrote on 13 Dec 2002 in
microsoft.public.scripting.VBScript:

Quote:
> Thanks for the help. The only problem is that the "right("00"+string,2) "
> doesnt work. Any ideas? Thanks,

You cannot have "'s inside "'s

& is preferred here as vbs string concatenator

It should be:

number = 5
mystring = right( "00" & number , 2 )

results in mystring = "05"

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)



Wed, 01 Jun 2005 01:32:13 GMT  
 Splitting a String
Hi,

Use & in place of + (+ coerces to numeric
for addition, and you want to keep it a string).

x= right("00" & n, 2)

Good luck,
Joe Earnest


Quote:
> Thanks for the help. The only problem is that the "right("00"+string,2) "
> doesnt work. Any ideas? Thanks,

> Chris



Wed, 01 Jun 2005 01:34:11 GMT  
 Splitting a String
Thats what I ended up doing. I got it. Thanks,

Chris


Quote:
> Chris Guimbellot wrote on 13 Dec 2002 in
> microsoft.public.scripting.vbscript:
> > Thanks for the help. The only problem is that the "right("00"+string,2)
"
> > doesnt work. Any ideas? Thanks,

> You cannot have "'s inside "'s

> & is preferred here as vbs string concatenator

> It should be:

> number = 5
> mystring = right( "00" & number , 2 )

> results in mystring = "05"

> --
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)



Wed, 01 Jun 2005 01:42:17 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Newbie wants to split up strings

2. Splitting a string into each character..

3. Splitting a string into an array

4. Splitting a string into each character..

5. cannot use split on string object

6. Q: howto split a string object

7. How to split this string

8. split a string based not on character but on length

9. Split a string variable

10. Split a String

11. Newbie question (split a string)

12. splitting a string in multiple parts

 

 
Powered by phpBB® Forum Software