Removes if starts with. - CSharp System

CSharp examples for System:String Strip

Description

Removes if starts with.

Demo Code


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

public class Main{
        /// <summary>
        /// Removes if starts with.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="text">The text.</param>
        /// <returns></returns>
        public static string RemoveIfStartsWith(this string source, string text)
        {
            if (string.IsNullOrEmpty(source) || string.IsNullOrEmpty(text))
            {
                return source;
            }

            if (!source.StartsWith(text))
            {
                return source;
            }

            return source.Remove(0, text.Length);
        }
}

Related Tutorials