Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.Split("//") is also picking up "/"

Tags:

asp.net

vb.net

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?

like image 848
webdad3 Avatar asked Sep 22 '10 21:09

webdad3


2 Answers

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)
like image 119
SLaks Avatar answered Sep 24 '22 02:09

SLaks


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'.

like image 25
MarkJ Avatar answered Sep 24 '22 02:09

MarkJ