How can I get URL from the text?
For example:
string Text = "this is text with url http://test.com";
I have to get url and set it to other variable. How can I do this with ASP.NET?
How can I get URL from the text?
For example:
string Text = "this is text with url http://test.com";
I have to get url and set it to other variable. How can I do this with ASP.NET?
String.Split Method (String[], StringSplitOptions)
http://msdn.microsoft.com/en-us/library/tabh47cf.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1
You can find examples: C# - C++ - F# - VB
[ComVisibleAttribute(false)]
public string[] Split(
string[] separator,
StringSplitOptions options
)
In this case, "http://" can be a good string for separator.
reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
This is the regex to find the URL from Text.
Hope Its Helpful.
string _Url = "this is text with url http://test.com";
MatchCollection _Match = Regex.Matches(_Url , @"http.+)([\s]|$)");
string _Address= _Match[0].Value.ToString();
U can use
"/(http|https|ftp|ftps)\://[a-zA-Z0-9-.]+.[a-zA-Z]{2,3}(/\S*)?/"
as regular expression for your search... ;)
Adding to the previous answers, you can do this as well:
string text = "this is text with url http://test.com";
Match match = Regex.Match(text, @"http\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(/\S*)?$");
// gets you http://test.com
string url = match.Value;