You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
2.5 KiB
78 lines
2.5 KiB
3 years ago
|
using System.Collections.Generic;
|
||
|
|
||
|
namespace BBWY.Client.Extensions
|
||
|
{
|
||
|
public static class ProcurementAuditExtension
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// 跳过引号中的逗号,进行逗号分隔(字段内容中的逗号不参与分隔)
|
||
|
/// </summary>
|
||
|
/// <param name="strLine"></param>
|
||
|
/// <returns></returns>
|
||
|
public static string[] CSVstrToArry(this string splitStr)
|
||
|
{
|
||
|
var newstr = string.Empty;
|
||
|
List<string> sList = new List<string>();
|
||
|
|
||
|
bool isSplice = false;
|
||
|
string[] array = splitStr.Split(new char[] { ',' });
|
||
|
foreach (var str in array)
|
||
|
{
|
||
|
if (!string.IsNullOrEmpty(str) && str.IndexOf('"') > -1)
|
||
|
{
|
||
|
var firstchar = str.Substring(0, 1);
|
||
|
var lastchar = string.Empty;
|
||
|
if (str.Length > 0)
|
||
|
{
|
||
|
lastchar = str.Substring(str.Length - 1, 1);
|
||
|
}
|
||
|
if (firstchar.Equals("\"") && !lastchar.Equals("\""))
|
||
|
{
|
||
|
isSplice = true;
|
||
|
}
|
||
|
if (lastchar.Equals("\""))
|
||
|
{
|
||
|
if (!isSplice)
|
||
|
newstr += str;
|
||
|
else
|
||
|
newstr = newstr + "," + str;
|
||
|
|
||
|
isSplice = false;
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (string.IsNullOrEmpty(newstr))
|
||
|
newstr += str;
|
||
|
}
|
||
|
|
||
|
if (isSplice)
|
||
|
{
|
||
|
//添加因拆分时丢失的逗号
|
||
|
if (string.IsNullOrEmpty(newstr))
|
||
|
newstr += str;
|
||
|
else
|
||
|
newstr = newstr + "," + str;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
sList.Add(newstr.Replace("\"", "").Trim());//去除字符中的双引号和首尾空格
|
||
|
newstr = string.Empty;
|
||
|
}
|
||
|
}
|
||
|
return sList.ToArray();
|
||
|
}
|
||
|
|
||
|
public static string FormatString(this string str)
|
||
|
{
|
||
|
//if (str.Contains(","))
|
||
|
// str = str.Replace(",", string.Empty);
|
||
|
if (str.Contains("\""))
|
||
|
str = str.Replace("\"", string.Empty);
|
||
|
if (str.Contains("\t"))
|
||
|
str = str.Replace("\t", string.Empty);
|
||
|
return str.Trim();
|
||
|
}
|
||
|
}
|
||
|
}
|