Removes trailing en ending single quotes from an E-mail address when they exist - CSharp System.Net.Mail

CSharp examples for System.Net.Mail:SmtpClient

Description

Removes trailing en ending single quotes from an E-mail address when they exist

Demo Code


using System.Text.RegularExpressions;

public class Main{
        #endregion/*ww w .ja  v a2  s. c  o m*/

        #region RemoveSingleQuotes
        /// <summary>
        /// Removes trailing en ending single quotes from an E-mail address when they exist
        /// </summary>
        /// <param name="email"></param>
        /// <returns></returns>
        public static string RemoveSingleQuotes(string email)
        {
            if (string.IsNullOrEmpty(email))
                return string.Empty;

            if (email.StartsWith("'"))
                email = email.Substring(1, email.Length - 1);

            if (email.EndsWith("'"))
                email = email.Substring(0, email.Length - 1);

            return email;
        }
}

Related Tutorials