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:

  1. "<table>"
  2. "<td>8172745</td>"
  3. "<td>8172745</td></table>"

however, receiving following array:

  1. ""
  2. "table>"
  3. "tr>"
  4. "td>8172745"
  5. "/td>"
  6. "tr>"
  7. "td>8172954"
  8. "/td>"
  9. "/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:

http://ideone.com/pcw6aq


Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -