比较两个字符串的方法永远不会返回正确的结果
这是一个独立的问题,与我在此提出的上一个问题有关。
我已在 gist.github 发布了完整源代码的副本,但我只有一个挥之不去的问题我无法解决。
FindLine()
始终返回 -1。我已经确认这两个变量正在传递良好的数据,所以我无法弄清楚为什么比较永远不会返回 -1 以外的任何内容。
如果您不想查看完整的源代码,这里是相关代码的片段:
DataTable resultTable = new DataTable();
string ImportPath = @"***PATH***\***INFILE***.csv";
string QueryString = "SELECT DISTINCT UPPER(MP.Symbol) AS Symbol, LOWER(MP.SecType) AS SecType, MBI.Status FROM MoxySecMaster AS MP LEFT JOIN MoxyBondInfo AS MBI ON MP.Symbol = MBI.Symbol AND MP.SecType = MBI.SecType WHERE MP.SecType <> 'caus' AND MP.SecType IS NOT NULL AND MP.Symbol IS NOT NULL ORDER BY Symbol ASC;";
string symb = "";
StringBuilder OrigText = new StringBuilder();
SqlConnection MoxyConn = new SqlConnection("server=***;database=***;user id=***;password=***");
SqlDataAdapter adapter = new SqlDataAdapter(QueryString, MoxyConn);
MoxyConn.Open();
resultTable = new DataTable();
adapter.Fill(resultTable);
MoxyConn.Close();
OrigText.Append(File.ReadAllText(ImportPath));
char[] tempSymb = new char[10];
OrigText.CopyTo(0, tempSymb, 0, OrigText.ToString().IndexOf(",", 0));
symb = new string(tempSymb);
int foundSpot = FindLine(symb, resultTable);
...和...
static int FindLine(string symbol, DataTable symbolList)
{
for (int vcl = 0; vcl < symbolList.Rows.Count; vcl++)
{
if (symbolList.Rows[vcl][0].ToString() == symbol.ToUpper())
return vcl;
}
return -1;
}
This is a separate problem lingering from a previous question I asked here on SO.
I've posted a copy of my full source at gist.github and I only have one lingering problem that I can't resolve.
FindLine()
always returns -1. I have confirmed that the two variables are getting passed good data, so I can't figure out why the comparisons never return anything other than -1.
Here's a snippet of the relevant code if you don't want to check out the full source:
DataTable resultTable = new DataTable();
string ImportPath = @"***PATH***\***INFILE***.csv";
string QueryString = "SELECT DISTINCT UPPER(MP.Symbol) AS Symbol, LOWER(MP.SecType) AS SecType, MBI.Status FROM MoxySecMaster AS MP LEFT JOIN MoxyBondInfo AS MBI ON MP.Symbol = MBI.Symbol AND MP.SecType = MBI.SecType WHERE MP.SecType <> 'caus' AND MP.SecType IS NOT NULL AND MP.Symbol IS NOT NULL ORDER BY Symbol ASC;";
string symb = "";
StringBuilder OrigText = new StringBuilder();
SqlConnection MoxyConn = new SqlConnection("server=***;database=***;user id=***;password=***");
SqlDataAdapter adapter = new SqlDataAdapter(QueryString, MoxyConn);
MoxyConn.Open();
resultTable = new DataTable();
adapter.Fill(resultTable);
MoxyConn.Close();
OrigText.Append(File.ReadAllText(ImportPath));
char[] tempSymb = new char[10];
OrigText.CopyTo(0, tempSymb, 0, OrigText.ToString().IndexOf(",", 0));
symb = new string(tempSymb);
int foundSpot = FindLine(symb, resultTable);
... and ...
static int FindLine(string symbol, DataTable symbolList)
{
for (int vcl = 0; vcl < symbolList.Rows.Count; vcl++)
{
if (symbolList.Rows[vcl][0].ToString() == symbol.ToUpper())
return vcl;
}
return -1;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用这个:
try using this: