Returns the rest of the string after the first occurrence of the string to find. If string not found, return the source string. - CSharp System

CSharp examples for System:String Search

Description

Returns the rest of the string after the first occurrence of the string to find. If string not found, return the source string.

Demo Code


using System;//from ww w .ja  v a2 s .  co m

public class Main{
        /// <summary>
        /// Returns the rest of the string after the first occurrence of the string to find.
        /// If string not found, return the source string.
        /// </summary>
        public
        static
        string
        After(
            this string source,
            string find)
        {
            int idx;

            return (idx = source.IndexOf(find)) == -1
                        ? source
                        : source.Substring(idx + find.Length);	// skip past the found character	
        }
}

Related Tutorials