Encode Tab Delimited - CSharp System

CSharp examples for System:String Encode Decode

Description

Encode Tab Delimited

Demo Code


using System.Text.RegularExpressions;
using System.Text;
using System.Linq;
using System.Globalization;
using System.ComponentModel;
using System.Collections.Generic;
using System;/*from   w  w  w  .  j  a v  a 2 s. c  o  m*/

public class Main{
        public static string EncodeTabDelimited(this string value)
        {
            var sbResult = new StringBuilder(value.Length * 3 / 2);
            foreach (var ch in value)
            {
                if (ch == '\t') sbResult.Append("\\t");
                else if (ch == '\n') sbResult.Append("\\n");
                else if (ch == '\r') sbResult.Append("\\r");
                else if (ch == '\'') sbResult.Append("\\\'");
                else if (ch == '\"') sbResult.Append("\\\"");
                else if (ch == '\\') sbResult.Append("\\\\");
                else
                {
                    sbResult.Append(ch);
                }
            }
            return sbResult.ToString();
        }
}

Related Tutorials