在 VB.NET 中是否有任何简单的方法来分割文本?
在 VB.NET 中是否有任何简单的方法来分割文本? (使用开始和结束字符串来获取中间的内容?)
我一直在 JScript 中使用以下命令执行此操作:
<前><代码><垃圾> <废话> <数据>someData1 <数据>someData2 <数据>someData3
var data = string.split('<data>')[1].split('</data>')[0];
通过将 [1] 索引更改为 [2] 会给我“someData1” 会很容易地给我“someData2”
由于某种原因,这似乎很难在 VB.NET 中实现。
这是我正在处理的实际 HTML 的一部分:
<...malformed html>
<div style='font-size:10pt;font-family:Times;color:#000000;position:absolute;top:2731.068;left:48'>Total</div>
<div style='font-size:10pt;font-family:Times;color:#000000;position:absolute;top:2731.068;left:346.2141'>18,072.59</div>
<div style='font-size:10pt;font-family:Times;color:#000000;position:absolute;top:2731.068;left:444.3433'>100.00%</div>
<div style='font-size:10pt;font-family:Times;color:#000000;position:absolute;top:2731.068;left:567.1293'>21,687.11</div>
<div style='font-size:10pt;font-family:Times;color:#000000;position:absolute;top:2731.068;left:666.3433'>100.00%</div>
<malformed html...>
我需要找到
Total
。 index 然后获取第 1 个和第 3 个 div 之间的数据。Is there any easy method for splitting text in VB.NET? (using a start and end string to grab whats in between?)
I do this all the time in JScript with the following:
<junk> <blah> <data>someData1</data> <data>someData2</data> <data>someData3</data> </blah> </junk>
var data = string.split('<data>')[1].split('</data>')[0];
would give me "someData1" by changing the [1] index to [2] would give me "someData2" very easy
for some reason this seems to be very difficult to achieve in VB.NET.
Here is a chunk of the actual HTML I'm dealing with:
<...malformed html>
<div style='font-size:10pt;font-family:Times;color:#000000;position:absolute;top:2731.068;left:48'>Total</div>
<div style='font-size:10pt;font-family:Times;color:#000000;position:absolute;top:2731.068;left:346.2141'>18,072.59</div>
<div style='font-size:10pt;font-family:Times;color:#000000;position:absolute;top:2731.068;left:444.3433'>100.00%</div>
<div style='font-size:10pt;font-family:Times;color:#000000;position:absolute;top:2731.068;left:567.1293'>21,687.11</div>
<div style='font-size:10pt;font-family:Times;color:#000000;position:absolute;top:2731.068;left:666.3433'>100.00%</div>
<malformed html...>
I need to find the <div>Total</div> index then grab the data between the 1st and 3rd divs after that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
编辑:
要解析 html,请尝试使用 Html Agility Pack
EDIT:
To parse html try using the Html Agility Pack
我让它工作了,尽管这是我写过的一些最糟糕的代码......
I got it working, although this is some of the worse code I've ever written...