當我運行以下代碼時,出現錯誤“startIndex 不能大于字串的長度。引數名稱:startIndex”。錯誤發生在這一行,我認為它與 line.substring 有關。當我取出 line.Substring(11, 2) = "24" 并將代碼運行為 If line.StartsWith("123") Then currentRecord.ID = line.
我似乎無法擺脫錯誤。
Dim lines = File.ReadLines(filePath)
If (line.StartsWith("123") And line.Substring(11, 2) = "24") Then currentRecord.ID = line
uj5u.com熱心網友回復:
您需要檢查該行是否足夠長以訪問該位置和長度的子字串。AndAlso 條件只會在前一個條件 = true 時觸發。如果您的 VB.NET 版本不支持 AndAlso,您將需要使用嵌套 if。
Dim lines = File.ReadLines(filePath)
If (line.StartsWith("123") AndAlso Len(line)>=14 AndAlso line.Substring(11, 2) = "24") Then currentRecord.ID = line
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/496426.html
標籤:VB.net
上一篇:如何設定按鈕以重置vbhtml中的搜索欄位并回傳初始視圖?
下一篇:創建自定義文本框
