.Split("//") is also picking up "/"
I am delimiting my data with the "//" as I am pass开发者_如何转开发ing 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?
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)
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'.
精彩评论