Remove Http from URL String - CSharp System

CSharp examples for System:String Strip

Description

Remove Http from URL String

Demo Code


using System.Text.RegularExpressions;
using System.Diagnostics;

public class Main{
        public static string RemoveHttp(string input)
        {/*from   w w  w .ja  v  a  2  s.  co m*/
            if (string.IsNullOrWhiteSpace(input))
            {
                return string.Empty;
            }
            var result = input;
            var matches = Regex.Matches(input, @"http[^\s]* ", RegexOptions.Compiled);
            foreach (Match match in matches)
            {
                result = result.Replace(match.Value, "");
            }

            var matches2 = Regex.Matches(result, @"http.*", RegexOptions.Compiled);
            foreach (Match match in matches2)
            {
                result = result.Replace(match.Value, "");
            }
            return result.TrimEnd();
        }
}

Related Tutorials