当我在 Visual Studio 上执行我的代码时,它运行良好,但是当我执行我的 exe 文件时,它会引发异常。
System.ArgumentOutOfRangeException: Index and length must refer to a location within the string.
Parameter name: length
at System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy)
at System.String.Substring(Int32 startIndex, Int32 length)
at QuoteExtractor.frmQuoteExtractor.cmdProcess_Click(Object sender, EventArgs e)
我的代码
private void cmdProcess_Click(object sender, EventArgs e)
{
try
{
foreach (string line in rtfMain.Lines)
{
try
{
if (line.Trim() != "")
{
if ((line != "") && (line != " ") && (line.Substring(0, 3) != "***") && (line.Substring(0, 5) != "CUSIP"))
{
Quote q = new Quote();
q.Parse(line);
DisplayQuote(q);
QuoteList.Add(q);
}
}
}
输入:
*** 9:30 AM ***
CUSIP BOND NAME SIZE CURR FACE TALK COVER PX
004421GU1 ACE 2004-HE2 M2 10.000MM 1.103MM dnt, 90 rsrv
61744CTZ9 MSHEL 2005-3 M3 4.720MM 4.720MM dnt