split adress and number?

M

martin

Hi, a very newbie question. How do I split the adress and number to 2
variables?
ex. "Kingsroad 347" = variabel1 = "Kingsroad" variabel2 = "347"

Ill guess i have to search the string from left to right after first
apperence of a number, but how do i do that?

Regards

Martin
 
R

Roland Hall

:
: Hi, a very newbie question. How do I split the adress and number to 2
: variables?
: ex. "Kingsroad 347" = variabel1 = "Kingsroad" variabel2 = "347"
:
: Ill guess i have to search the string from left to right after first
: apperence of a number, but how do i do that?

dim myString, myArray
myString = "Kingsroad 347"
myArray = Split(myString, " ")
Response.Write(myArray(0)) '---- Kingsroad
Response.Write(myArray(1)) '---- 347

or

dim myString, myArray, i
myString = "Kingsroad 347"
myArray = Split(myString, " ")
for i = lbound(myArray) to ubound(myArray)
Response.Write(myArray(i) & "<br />" & vbCrLf)
next

HTH...

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
 
M

martin

Roland Hall said:
:
: Hi, a very newbie question. How do I split the adress and number to 2
: variables?
: ex. "Kingsroad 347" = variabel1 = "Kingsroad" variabel2 = "347"
:
: Ill guess i have to search the string from left to right after first
: apperence of a number, but how do i do that?

dim myString, myArray
myString = "Kingsroad 347"
myArray = Split(myString, " ")
Response.Write(myArray(0)) '---- Kingsroad
Response.Write(myArray(1)) '---- 347

or

dim myString, myArray, i
myString = "Kingsroad 347"
myArray = Split(myString, " ")
for i = lbound(myArray) to ubound(myArray)
Response.Write(myArray(i) & "<br />" & vbCrLf)
next

Thanks alot, but both of your solutions split the string at the first
space(" ").
Is it possible to split at the first apperence of a number.. cos with this
solution it would be a problem if the user had typed in "Kin gsroad 347". Or
am i wrong?


regards

Martin
 
B

Bob Barrows

martin said:
Thanks alot, but both of your solutions split the string at the first
space(" ").
Is it possible to split at the first apperence of a number.. cos
with this solution it would be a problem if the user had typed in
"Kin gsroad 347". Or am i wrong?
What if the street name contains a number?

Bob Barrows
 
M

martin

Bob Barrows said:
What if the street name contains a number?

Well, in Sweden they dont. But good question.
Is it possible to split a string at first apperence of a number?

/martin
 
R

Roland Hall

in message
:
: > What if the street name contains a number?
:
: Well, in Sweden they dont. But good question.
: Is it possible to split a string at first apperence of a number?
:
: /martin

Yes, you can do it however you want but you need to have a little
consistency.
Is there a limit on the number of digits?
Do you not want to allow any spaces except between name and number?
What if you had this? Kings Road 3 4 7
Or this? 347 Kingsroad, 347 kings road, 347 KiNGS-RoaD

You could correct this with regular expressions and with using the replace
function but I wouldn't it be easier to require the user to know how to type
in their correct address? In other words, if you are expecting only 1
space, I'd first check to see if there is more than one and if so, return it
back to the user and tell them try again.
Perhaps if you can tell us the known requirements, it would help to devise
something usable.
We need to know what you expect, what you will accept, what the boundaries
are and the order you'd like to have them.

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
 
D

Don Verhagen

Roland Hall said:
in message
:
: > What if the street name contains a number?
:
: Well, in Sweden they dont. But good question.
: Is it possible to split a string at first apperence of a number?
:
: /martin

Yes, you can do it however you want but you need to have a little
consistency.
Is there a limit on the number of digits?
Do you not want to allow any spaces except between name and number?
What if you had this? Kings Road 3 4 7
Or this? 347 Kingsroad, 347 kings road, 347 KiNGS-RoaD

You could correct this with regular expressions and with using the replace
function but I wouldn't it be easier to require the user to know how to type
in their correct address? In other words, if you are expecting only 1
space, I'd first check to see if there is more than one and if so, return it
back to the user and tell them try again.
Perhaps if you can tell us the known requirements, it would help to devise
something usable.
We need to know what you expect, what you will accept, what the boundaries
are and the order you'd like to have them.
If this is data you are requesting then ask for it in seperate form fields
otherwise there are tons of data cleansing methods.

Example:

House Number: 347
Street: Kingsroad
Suite/Apt/Unit: 123

Don Verhagen
 
V

Vilmar Brazão de Oliveira

Hi,
In the time of keep away the datas in your database you can put some
especial signs in the end of your address like:
==|== (2 equals signs, one pipe sign and 2 equals signs), for example,
I believe that there is not this kind of signs in any street address of any
part of the world.
So you can always split the address using these special signs:
dim myString, myArray
myString = "Kingsroad 347"
myArray = Split(myString, "==|==")
Response.Write(myArray(0)) '---- Kingsroad
Response.Write(myArray(1)) '---- 347

Hope this help.
--

Sem mais,

««««««««»»»»»»»»»»»»»»
Vlmar Brazão de Oliveira
Desenvolvimento Web
HI-TEC
 
R

Roland Hall

:
: If this is data you are requesting then ask for it in seperate form fields
: otherwise there are tons of data cleansing methods.
:
: Example:
:
: House Number: 347
: Street: Kingsroad
: Suite/Apt/Unit: 123

Good idea Don. That would cut down on the confusion and testing.

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
 
B

Bob Barrows [MVP]

martin said:
Well, in Sweden they dont. But good question.
Is it possible to split a string at first apperence of a number?

/martin

Well, I wanted to play, so here's a non-regex method:

dim sAddress, sNumber, sName, iPos

If Instr('0123456789', left(sAddress,1))>0 then
'number appears first in address
iPos = InStr(sAddress, " ")
sNumber=left(sAddress,iPos-1)
sName=mid(sAddress,iPos + 1)
else
'assume number appears last, preceded with a space, and
' with no following characters
iPos = InStr(sAddress, " ")
sNumber=mid(sAddress,iPos+1)
sName=left(sAddress,iPos - 1)
end if

You can use this as a model for testing for other conditions.

HTH,
Bob Barrows
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,146
Messages
2,570,831
Members
47,374
Latest member
anuragag27

Latest Threads

Top