hi...Everything before the first match is returned as the first element.
A.Venkatesan
Microsoft Certified Professional
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact venkatmca008@gmail.com
Marked as answer by seanad on Mar 02, 2012 05:24 AM
Dim ff As String = ""
Dim FF1 As String() = ff.Split(",")
MsgBox(FF1.Length)
it will return 1 beacuse...
ff.Split(",") return "" that means empty string It count as single element to FF1(0)
So ff1.length=1
A.Venkatesan
Microsoft Certified Professional
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact venkatmca008@gmail.com
hi...u can try with F10 then will know what i am trying to tell u
example if i have
dim ff as string="1,2,3"
if i split ff1 will have
ff1(0)=1
ff1(1)=2
ff1(2)=3
ff.Split(",") return 1 2 3
dim ff as string=""
if i split ff1 will have
Ff1(0)=""
ff.Split(",") return ""
A.Venkatesan
Microsoft Certified Professional
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact venkatmca008@gmail.com
Answer is already provided by Venkatesan. I'll try to clear it up more and add more info.
seanad
var s = str.split(";");
This will return an array so the s will be an array.
seanad
document.write("##" + s + "##<br />");
Here you are trying to get the value of array but you haven't specified an index, So if you try s[0], you will see the same result, but the variable is different though the value is same.
seanad
document.write("len=" + s.length);
This will return 1 because when you call the split method on empty string, it will return an array with one empty element, instead of returning an empty array. So the array itself is not empty. It has
one empty element.
seanad
Member
36 Points
41 Posts
The string's length
Mar 01, 2012 04:45 AM|LINK
Hi all,
Anyone knows why below string s.length = 1? str is an empty string. TIA
<html> <body> <script type="text/javascript"> var str=""; var s = str.split(";"); document.write("##" + s + "##<br />"); document.write("len=" + s.length); </script> </body> </html>venkatmca008
Participant
1810 Points
341 Posts
Re: The string's length
Mar 01, 2012 04:56 AM|LINK
hi...Everything before the first match is returned as the first element.
Microsoft Certified Professional
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact venkatmca008@gmail.com
daisydain
Member
222 Points
51 Posts
Re: The string's length
Mar 01, 2012 04:57 AM|LINK
Hello,
try "alert(s)" to see the string value i am sure its not "" . It may have one balnk space
venkatmca008
Participant
1810 Points
341 Posts
Re: The string's length
Mar 01, 2012 05:02 AM|LINK
HI...u didnt understand what i said
Dim ff As String = "" Dim FF1 As String() = ff.Split(",") MsgBox(FF1.Length) it will return 1 beacuse... ff.Split(",") return "" that means empty string It count as single element to FF1(0)Microsoft Certified Professional
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact venkatmca008@gmail.com
ny2244111
Member
184 Points
34 Posts
Re: The string's length
Mar 01, 2012 05:07 AM|LINK
What I think venkat is saying is s is not a string but an array of strings.
venkatmca008
Participant
1810 Points
341 Posts
Re: The string's length
Mar 01, 2012 05:13 AM|LINK
hi...u can try with F10 then will know what i am trying to tell u
Microsoft Certified Professional
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact venkatmca008@gmail.com
Danny Gokey
Member
290 Points
56 Posts
Re: The string's length
Mar 01, 2012 06:33 AM|LINK
Hi,
like the Ven said, the str.split(";") will returen " ", even the str is empty, so the length is 1, maybe you can try to remove the separator,
then it will return the length as 0.
shafkatlee
Member
152 Points
53 Posts
Re: The string's length
Mar 01, 2012 07:19 AM|LINK
Hi,
Null is also a character.
roopeshreddy
All-Star
20155 Points
3328 Posts
Re: The string's length
Mar 01, 2012 09:22 AM|LINK
Hi,
If you use empty string for split() function, then it will return the entire string!
In your case it's empty, hence 1.
http://www.w3schools.com/jsref/jsref_split.asp
In the above link, check the parameter description!
Hope it helps u...
Roopesh Reddy C
Roopesh's Space
Ruchira
All-Star
42999 Points
7027 Posts
MVP
Re: The string's length
Mar 01, 2012 09:33 AM|LINK
Hi,
Answer is already provided by Venkatesan. I'll try to clear it up more and add more info.
This will return an array so the s will be an array.
Here you are trying to get the value of array but you haven't specified an index, So if you try s[0], you will see the same result, but the variable is different though the value is same.
This will return 1 because when you call the split method on empty string, it will return an array with one empty element, instead of returning an empty array. So the array itself is not empty. It has one empty element.
Hope it clears up the problem now..
My Tech blog | My YouTube ChannelPlease 'Mark as Answer' if this post helps you.