tags:

views:

177

answers:

2

I am delimiting my data with the "//" as I am passing it up to my webservice. My webservice is splitting the data into an array like so:

myArray = al(i).ToString.Split("//")

Everything works great, however, if I pass in some data like this: 100/100 then that also gets split. Is there a way to make sure that only the "//" gets split?

+20  A: 

The VB.Net compiler is converting your string into a Char array and calling this overload.
Thus, it's splitting on either / or /.

You need to call the overload that takes a string array, like this:

"100/100".Split(New String() { "//" }, StringSplitOptions.None)
SLaks
AH! That took me a second to figure out. That's just plain *nasty*! The string is really a character array containing '/' and '/'. YIKES!
Jon B
Should the example be "100//100" ?
izb
@izb: No. He specifically wants that string to not split.
SLaks
indeed, he recently added the vb.net tag, +1 regardless
Woot4Moo
Thanks all, this worked great! I appreciate all the tips too!
Jeff V
+1 and if you use `Option Strict` the [VB compiler will give an error](http://stackoverflow.com/questions/3773618/split-is-also-picking-up/3780058#3780058) rather than choosing this unhelpful overload
MarkJ
+2  A: 

Always, always use Option Strict.

With Option Strict the original code produces an error, rather than choosing the unhelpful overload:

Error 1 Option Strict On disallows implicit conversions from 'String' to 'Char'.

MarkJ
+1 I don't care how relevant, this is ALWAYS good advice.
Andy_Vulhop
@Mark - Thank you for that answer and will make that change in my code. I'm a little confused as to why "//" isn't a string in the 1st place? If you have a reference that I can read up on this issue that would be great! Also what would you have done if you had gotten this error?
Jeff V
@Jeff If I had got the error, I would have checked the available overloads for Split and seen that there wasn't one that accepts a string. I hope I would then have figured out another way to get the result I wanted. My answer has a link to the docs on Option Strict, that's a good starting point.
MarkJ
@Mark - Thanks!
Jeff V