BatchGuy.App.Extensions.ExtensionMethods.RemoveBackspaces C# (CSharp) Method

RemoveBackspaces() public static method

public static RemoveBackspaces ( this value ) : string
value this
return string
        public static string RemoveBackspaces(this string value)
        {
            if (string.IsNullOrEmpty(value)) //put -1 for last index of as well
                return value;

            int lastOccurrence = value.LastIndexOf('\b');

            if (lastOccurrence == -1)
                return value;

            lastOccurrence += 1;

            StringBuilder result = new StringBuilder((value.Length - lastOccurrence) + 1);
            result.Append(value.Substring(lastOccurrence,  (value.Length - lastOccurrence)));

            return result.ToString().Trim();
        }