Remove Last Symbol If Exists - CSharp System

CSharp examples for System:String Strip

Description

Remove Last Symbol If Exists

Demo Code


using System.Text.RegularExpressions;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;//  www  .j  ava  2 s.co  m

public class Main{
        public static string RemoveLastSymbolIfExists(this string src, char symbol)
        {
            if (string.IsNullOrEmpty(src))
                return src;

            return src[src.Length - 1] == symbol ? src.Substring(0, src.Length - 1) : src;
        }
}

Related Tutorials