问个字符串的split问题
代码如下:
strPart = strSource.Split( " <tr align=center ")
strSource的内容如下:
<br> <span class=odds> 0.925 </span> </td> </tr> <tr align=center bgcolor=#ffffff> <td height=35 bgcolor= '#6f00dd '> <font color=#ffffff>
我的想法是得到
" <br> <span class=odds> fdsa </span> </td> </tr> "
和 "bgcolor=#ffffff> <td height=35 bgcolor= '#6f00dd '> <font color=#ffffff> "
这样两个字符串,可为何得到的结果却是把所有的> <里的内容全都拆分成了N个数组元素而不是两个元素呢?
盼高人给解答~
[解决办法]
Imports Microsoft.VisualBasic
strPart = Split(strSource, " <tr align=center ")
或者
Dim splitstr() As String = { " <tr align=center "}
strPart = strSource.Split(splitstr, StringSplitOptions.None)
[解决办法]
没错,因为String.Split方法的参数是char,即字符或字符数组,所以你的代码按照 " <tr align=center "的首字符 " < "分割了.
Public Class Form1
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a As String = " <br/> <span class=odds> 0.925 </span> </td> </tr> <tr align=center bgcolor=#ffffff> <td height=35 bgcolor= '#6f00dd '> <font color=#ffffff> "
Dim b() As String = Split(a, " <tr align=center ")
Dim i As Int32
For i = 0 To b.GetUpperBound(0)
MsgBox(b(i))
Next
End Sub
End Class