0

所以我在这里有这个 HTML:

<div id="verify-purchase-modal" data-role="dialog">
    <div data-role="header">
        <h1>Buy Item</h1>
    </div>
    <div data-role="content">
<form action="/Catalog/ProcessPurchase" method="post">              <div></div>
                <div class="catalog-modal-image">
                        <img src="http://t6ak.roblox.com/cd4fad953f57e86e537da262b3503e04" alt="General Badblox" />

                </div>
                <div>
                    Would you like to buy the <strong>"General Badblox"</strong> Package
                    from ROBLOX for
                        <span class="currency-robux">400</span>?
                </div>
                <div class="ui-grid-a no-margin-grid add-large-margin-top clear">
                    <div class="ui-block-a">
                        <input name="__RequestVerificationToken" type="hidden" value="9EZgfWvmFbfVWWSvuIhMrWWs6E2XmjONlejy5JJRYQh5KBbttyCtH/ve1KcPq1MbLYnj6ktT8SyGfFrWRYshUMLUI1mmthTs1KJNizlPG8T809is5Y0ZJYJyqaTCmnom2P6vVpmnZATlqsFtN4pVhd1QH94cZbLU2eszES4+QLeES2Cv" />
                        <input data-val="true" data-val-number="The field CurrencyType must be a number." data-val-required="The CurrencyType field is required." id="CurrencyType" name="CurrencyType" type="hidden" value="1" />
                        <input data-val="true" data-val-number="The field AssetID must be a number." data-val-required="The AssetID field is required." id="AssetID" name="AssetID" type="hidden" value="98755232" />
                        <input data-val="true" data-val-number="The field UserAssetOptionID must be a number." data-val-required="The UserAssetOptionID field is required." id="UserAssetOptionID" name="UserAssetOptionID" type="hidden" value="0" />
                        <input type="submit" value="Buy Now" data-theme="d" />
                    </div>
                    <div class="ui-block-b">
                        <a id="cancelPurchase" data-rel="back" data-role="button" data-theme="f">Cancel</a>
                    </div>
                </div>
                    <div class="dialog-footnote">
                        Your balance after this transaction will be <span class="currency-robux">11,910</span>.
                    </div>
</form>
    </div>
</div>

我用VB从一个网站上得到它。在写着“400?”的那一行。我想提取 400,所以我将所有 HTML 保存为字符串。我试图做简单的事情,只使用一个子字符串来获取它,但我不断收到 OOB(越界)错误。请记住,我正在尝试在 Visual Basic 中执行此操作。

        Dim daHtml As String = WebBrowser1.Document.Body.OuterHtml
    Msg(daHtml.Substring(daHtml.IndexOf("currency-robux"">"), daHtml.IndexOf("</span>?")))
4

1 回答 1

0

在 VB 中,子字符串的工作方式与其他语言不同。错了,在我看来。而不是 substring(startIndex, endIndex) 它是 substring (startIndex, length)。所以你正在寻找从以下开始的东西:

daHTML.IndexOf("currency-robux"">")

长度为:

daHTML.indexOf("</span>?")

因此,超出了字符串的范围。

于 2012-12-08T03:42:44.270 回答