vb.net - String.Split returning incorrect array -
attempting correct html table incorrectly formatted. not have control on source, application loads contents of downloaded file regular text file. file contents simple html table missing closing </tr> elements. i'm attempting split contents on <tr> array can </tr> end of elements need it. when attempt split string using flecontents.split("<tr>").tolist i'm getting lot more elements in resulting list(of string) there should be.
here short little test code shows same behavior:
dim testsource string = "<table><tr><td>8172745</td><tr><td>8172745</td></table>" dim testarr string() = testsource.split("<tr>") 'maybe try splitting on variable because can't use string literal containging "<>" in split method dim seper string = "<tr>" testarr string() = testsource.split(seper) 'feed new string directly testarr = testsource .split(new string("<tr>")) i expect testarr should contain 3 elements, follows:
"<table>""<td>8172745</td>""<td>8172745</td></table>"
however, receiving following array:
"""table>""tr>""td>8172745""/td>""tr>""td>8172954""/td>""/table>"
can please explain why strings being split way , how can go getting results i'm expecting?
your code using different overload of split method you're expecting. want method takes string[] , stringsplitoptions parameter:
dim testsource string = "<table><tr><td>8172745</td><tr><td>8172745</td></table>" dim delimeter string() = { "<tr>" } dim testarr string() = _ testsource.split(delimeter, stringsplitoptions.removeemptyentries) you can see working @ ideone:
Comments
Post a Comment