This commit is contained in:
“wanyongkang”
2020-12-28 14:55:48 +08:00
parent c2ec7392cb
commit 40a40b6d36
305 changed files with 20629 additions and 20629 deletions

View File

@@ -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;
}
}
}