我的文本文件包含以下内容
wYFgemq4-IU372t5I-J0UIIdAd-gcojGR7z BA1111111
HoSOtYLI-90yntvqB-2rV/RLiG-BT69R0NV BA1111111
h1uLXWq4-IU2QUkVr-UYuqipiT-byAuoHn7 BG2222222
jL2MFmq4-IU1VLifN-LZmFc+bu-ibc/2IJp GC1111111
zhoZpmq4-IU27lkQ1-kqNLXTbT-ec28qGPR FG1111111
但遗憾的是,在第5行末尾还有一个空格正在添加,我上传文件时收到错误...
如何删除第五行末尾的空格(即) zhoZpmq4-IU27lkQ1-kqNLXTbT-ec28qGPR FG1111111(在这里)
任何人都可以帮忙吗
这是我的代码
private bool ParseUploadedDoc(string strUpload)
{
bool blresult = true;
strUpload = strUpload.Replace("\r","");
char [] delimitedchars = {'\n'};
string[] splitwords = strUpload.Split(delimitedchars);
string[] column;
StringBuilder InvalidCert = new StringBuilder();
StringBuilder InvalidSerial = new StringBuilder();
foreach (string word in splitwords)
{
column = word.Split('\t');
column[1].Trim();
if (column[0].Length != 35)
{
InvalidCert.Append(column[0].ToString());
InvalidCert.Append(", ");
blresult = false;
}
/// getting error at here
if (column[1].Length != 9)
{
InvalidSerial.Append(column[1].ToString());
InvalidSerial.Append(", ");
blresult = false;
}
}
if (blresult == false)
{
string strErrCert = "Invalid Certificate Id(s): " + InvalidCert.ToString();
strErrCert = strErrCert.Substring(0, strErrCert.Length - 2);
LblInvalidCert.Text = strErrCert;
string strErrFru = "Invalid Serial Number(s): " + InvalidSerial.ToString();
strErrFru = strErrFru.Substring(0, strErrFru.Length - 2);
LblInvalidFru.Text = strErrFru;
}
return blresult;
}
答案 0 :(得分:4)
问题出在这一行
column[1].Trim();
你应该做
column[1] = column[1].Trim();