|
 |
aspx_beginners thread: Test array size?
Message #1 by "John Hamman {Hamman Interactive}" <johnhamman@C...> on Sat, 4 May 2002 20:40:43 -0400
|
|
Hi all,
Question: How do I test an arrray for how many splits it has? For example; I
split the folowing string "Antique.Irons.123" by the '.' If i did that I
should have a1=Antique,a2=Irons,& a3=123. I would have 3 segements in the
array. But if i split the string "Antique.Irons" by the '.' I would only
have 2 segments. What is the proper VB code for me to check if the 3rd
Segement exist?
thanks
John
Message #2 by "Glenn Euloth" <eulothg@h...> on Tue, 7 May 2002 09:05:58 -0300
|
|
> Hi all,
> Question: How do I test an arrray for how many splits it has? For
> example; I
> split the folowing string "Antique.Irons.123" by the '.' If i did that I
> should have a1=Antique,a2=Irons,& a3=123. I would have 3 segements in the
> array. But if i split the string "Antique.Irons" by the '.' I would only
> have 2 segments. What is the proper VB code for me to check if the 3rd
> Segement exist?
> thanks
> John
Here's how I would have done it in straight ASP and I don't think that's
changed much in the .Net version. In fact, just tried it as an ASPX file
and it worked. The key, of course, is the UBound function which returns the
index of the last item in the array. Remember that arrays are zero based so
you have to add 1 to get the count of items but you start looking at index
0!
<%
DIM MyArray, i
MyArray = split("Antique.Irons.123",".")
Response.Write("<ol>")
For i = 0 to UBound(MyArray)
Response.Write("<li>" & MyArray(i))
Next i
Response.Write("</ol>")
Response.Write("<p>Number of items = " & UBound(MyArray) + 1 & "</p>")
%>
Message #3 by "Minh T. Nguyen" <nguyentriminh@y...> on Tue, 7 May 2002 10:11:52 -0700
|
|
Glenn, John,
You can also just use MyArray.Length which will return you the
length of the array.
Minh.
-----Original Message-----
From: Glenn Euloth [mailto:eulothg@h...]
Sent: Tuesday, May 07, 2002 5:06 AM
To: aspx_beginners
Subject: [aspx_beginners] RE: Test array size?
> Hi all,
> Question: How do I test an arrray for how many splits it has? For
> example; I
> split the folowing string "Antique.Irons.123" by the '.' If i did that
I
> should have a1=Antique,a2=Irons,& a3=123. I would have 3 segements in
the
> array. But if i split the string "Antique.Irons" by the '.' I would
only
> have 2 segments. What is the proper VB code for me to check if the 3rd
> Segement exist?
> thanks
> John
Here's how I would have done it in straight ASP and I don't think that's
changed much in the .Net version. In fact, just tried it as an ASPX
file
and it worked. The key, of course, is the UBound function which returns
the
index of the last item in the array. Remember that arrays are zero
based so
you have to add 1 to get the count of items but you start looking at
index
0!
<%
DIM MyArray, i
MyArray = split("Antique.Irons.123",".")
Response.Write("<ol>")
For i = 0 to UBound(MyArray)
Response.Write("<li>" & MyArray(i))
Next i
Response.Write("</ol>")
Response.Write("<p>Number of items = " & UBound(MyArray) + 1 & "</p>")
%>
|
|
 |