从字符串中删除* [英] Remove * from string
本文介绍了从字符串中删除*的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在上传CSV文件,但是CSV文件中的数据字段之一可能在末尾标有*,即SI 9 MS *,我想在将此数据上传到D B.我该怎么做呢?我正在读取我的CSV文件,如下所示:
I''m working with uploading a CSV file but one of the data fields in the CSV file maybe marked with a * at the end i.e. SI 9 MS*, I want to remove this * char before uploading this data to the DB. How do I do this? I''m reading my CSV file like this:
//Read in contents of file into database
using (CsvReader reader = new CsvReader(strFolderPath + @"\" + strFileName))
{
int intCounter = 0;
foreach (string[] values in reader.RowEnumerator)
{
//NOTE: First 4 rows are header information
if (reader.RowIndex > 4)
{
if (DAL.InsertPriceList(RegionID, values, Session["Username"].ToString()))
{
//throw new Exception("Row " + (intCounter+1).ToString() + " - " + DAL.DBErrorMsg);
if (DAL.DBErrorMsg != "")
{
StringBuilder errormessage = new StringBuilder();
errormessage.Append(DAL.DBErrorMsg);
}
}
intCounter++;
}
}
lblUploadSuccess.Text = string.Format("{0} Price List items uploaded to database", intCounter);
lblUploadSuccess.Visible = true;
PopulatePriceListGridView();
}
推荐答案
尝试一下:
Try this:
//Read in contents of file into database
using (CsvReader reader = new CsvReader(strFolderPath + @"\" + strFileName))
{
int intCounter = 0;
foreach (string[] values in reader.RowEnumerator)
{
//Removing * from values
string[] newVal = new string[values.Length];
int count = 0;
foreach (string val in values)
{
newVal[count] = val.Replace("*", "");
count++;
}
//NOTE: First 4 rows are header information
if (reader.RowIndex > 4)
{
if (DAL.InsertPriceList(RegionID, newVal, Session["Username"].ToString()))
{
//throw new Exception("Row " + (intCounter+1).ToString() + " - " + DAL.DBErrorMsg);
if (DAL.DBErrorMsg != "")
{
StringBuilder errormessage = new StringBuilder();
errormessage.Append(DAL.DBErrorMsg);
}
}
intCounter++;
}
}
lblUploadSuccess.Text = string.Format("{0} Price List items uploaded to database", intCounter);
lblUploadSuccess.Visible = true;
PopulatePriceListGridView();
}
--Amit
--Amit
这篇关于从字符串中删除*的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文