忽略
This commit is contained in:
@@ -1,49 +1,49 @@
|
||||
using System.Text;
|
||||
|
||||
namespace Hncore.Infrastructure.CSV
|
||||
{
|
||||
public class CsvRow
|
||||
{
|
||||
private string _content = "";
|
||||
|
||||
public CsvRow AddCell(string content)
|
||||
{
|
||||
if (_content != "")
|
||||
{
|
||||
_content += ",";
|
||||
}
|
||||
|
||||
_content += StringToCsvCell(content);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return _content;
|
||||
}
|
||||
|
||||
private static string StringToCsvCell(string str)
|
||||
{
|
||||
bool mustQuote = str.Contains(",") || str.Contains("\"") || str.Contains("\r") || str.Contains("\n");
|
||||
if (mustQuote)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append("\"");
|
||||
foreach (char nextChar in str)
|
||||
{
|
||||
sb.Append(nextChar);
|
||||
if (nextChar == '"')
|
||||
{
|
||||
sb.Append("\"");
|
||||
}
|
||||
}
|
||||
|
||||
sb.Append("\"");
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
}
|
||||
using System.Text;
|
||||
|
||||
namespace Hncore.Infrastructure.CSV
|
||||
{
|
||||
public class CsvRow
|
||||
{
|
||||
private string _content = "";
|
||||
|
||||
public CsvRow AddCell(string content)
|
||||
{
|
||||
if (_content != "")
|
||||
{
|
||||
_content += ",";
|
||||
}
|
||||
|
||||
_content += StringToCsvCell(content);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return _content;
|
||||
}
|
||||
|
||||
private static string StringToCsvCell(string str)
|
||||
{
|
||||
bool mustQuote = str.Contains(",") || str.Contains("\"") || str.Contains("\r") || str.Contains("\n");
|
||||
if (mustQuote)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append("\"");
|
||||
foreach (char nextChar in str)
|
||||
{
|
||||
sb.Append(nextChar);
|
||||
if (nextChar == '"')
|
||||
{
|
||||
sb.Append("\"");
|
||||
}
|
||||
}
|
||||
|
||||
sb.Append("\"");
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user