Decode Tab Delimited - CSharp System

CSharp examples for System:String Encode Decode

Description

Decode 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;/*w ww. j a  v a2  s  . c o  m*/

public class Main{
        #region TAB-delimited backslash-escaped formatting

        public static string DecodeTabDelimited(this string value)
        {
            var length = value.Length;
            var sbDecoded = new StringBuilder(length);
            for (var i = 0; i < length; ++i)
            {
                var ch = value[i];
                if (ch == '\\')
                {
                    ++i;
                    if (i >= length)
                    {
                        // throw exception?
                        break;
                    }
                    switch (value[i])
                    {
                        case 't':
                            sbDecoded.Append('\t');
                            break;
                        case 'n':
                            sbDecoded.Append('\n');
                            break;
                        case 'r':
                            sbDecoded.Append('\r');
                            break;
                        case '\'':
                            sbDecoded.Append('\'');
                            break;
                        case '\"':
                            sbDecoded.Append('\"');
                            break;
                        case '\\':
                            sbDecoded.Append('\\');
                            break;
                    }
                }
                else sbDecoded.Append(ch);
            }
            return sbDecoded.ToString();
        }
}

Related Tutorials