Exemple #1
0
        public string Serialize()
        {
            StrGen.Builder builder = StrGen.GetBuilder();

            int lastRow = 0;

            DoCell((row, col, cellValue) => {
                if (row != lastRow)
                {
                    builder.Append("\n"); lastRow = row;
                }
                if (col != 0)
                {
                    builder.Append(",");
                }
                AppendString(builder, cellValue);
            });
            return(builder.GetStringAndRelease());
        }
Exemple #2
0
 static void AppendString(StrGen.Builder sb, string cellValue)
 {
     if (null == cellValue)
     {
         cellValue = "";
     }
     else
     {
         cellValue = cellValue.Replace("\n", "\\n");
         if (cellValue.IndexOfAny(",\"".ToCharArray()) >= 0)
         {
             cellValue = cellValue.Replace("\"", "\"\"");
             sb.AppendFormat("\"{0}\"", cellValue);
             return;
         }
     }
     sb.Append(cellValue);
 }