OrE*_*lse 1 .net vb.net string indexof
有人能指出我为什么IndexOf在下面的文本中总是返回零?
Dim Str as string = "<p><img class=floatLeft width="330"src="http://www.com"></p><p>"
Dim Idx as integer = Str.IndexOf("<p>")
Run Code Online (Sandbox Code Playgroud)
获取索引还有其他方法吗?
因为第一次出现<p>是在字符串的开头和字符串(与许多其他的东西一起)是零索引.
如果要获取上次发生的索引<p>,可以使用Str.LastIndexOf("<p>").
如果你想获得的指数下一个 -occurring <p>第一后,并假设这个字符串总是开始与至少一个<p>,就可以使用Str.IndexOf("<p>", "<p>".Length()),因此从开始第一次出现后搜索.
顺便说一句,你的行中有一个语法错误Dim Str,你需要使用额外的双引号来转义双引号:
Dim Str as string = "<p><img class=""floatLeft"" width=""330"" src=""http://www.com""></p><p>"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
320 次 |
| 最近记录: |