如何在 Ruby 中用 <br> 拆分字符串
How to split a string with <br> in Ruby
我正在使用 Nokogiri 在网页上搜索一些信息。找到它后,我得到以下字符串:
<p></p>
<p>Spiegel Institut Communication GmbH & Co. KG i. G.<br>Eastsite
VI<br>Hermsheimer Straße 5<br>D-68163 Mannheim<br>Telefon: +49 621-728 44-
444<br>Telefax: +49 621-728 44-445<br>E-Mail: b.weber@spiegel-
institut.de<br>Geschäftsführer:<br>Dipl.-Kfm. Götz Spiegel<br>Amtsgericht
Mannheim<br>Inhaltlich Verantwortlicher gemäß § 10 Absatz 3 MDStV: Götz
Spiegel (Anschrift wie oben)</p>
都是一行。我想将
上的字符串分隔成一个新行,这样我就可以从中获取单个详细信息。我该怎么做?我是 Ruby 的新手,我已经尝试过了,但不知何故我无法获得我想要的结果。
非常感谢
你可以直接使用split方法:
string.split('<br>')
比较简单,对字符串使用split方法。例如:
'this<br>that<br> the other'.split("<br>")
将导致
["this", "that", " the other"]
我正在使用 Nokogiri 在网页上搜索一些信息。找到它后,我得到以下字符串:
<p></p>
<p>Spiegel Institut Communication GmbH & Co. KG i. G.<br>Eastsite
VI<br>Hermsheimer Straße 5<br>D-68163 Mannheim<br>Telefon: +49 621-728 44-
444<br>Telefax: +49 621-728 44-445<br>E-Mail: b.weber@spiegel-
institut.de<br>Geschäftsführer:<br>Dipl.-Kfm. Götz Spiegel<br>Amtsgericht
Mannheim<br>Inhaltlich Verantwortlicher gemäß § 10 Absatz 3 MDStV: Götz
Spiegel (Anschrift wie oben)</p>
都是一行。我想将
上的字符串分隔成一个新行,这样我就可以从中获取单个详细信息。我该怎么做?我是 Ruby 的新手,我已经尝试过了,但不知何故我无法获得我想要的结果。
非常感谢
你可以直接使用split方法:
string.split('<br>')
比较简单,对字符串使用split方法。例如:
'this<br>that<br> the other'.split("<br>")
将导致
["this", "that", " the other"]