How to get text from a textbox, between two points
You should be more specific in your question, I think. Now, if you just want to extract the middle part of the address, do the following:
var parts = textbox.Text.Split(new char[] {'.'});
if (parts.Length < 3) throw new InvalidOperationException("Invalid address.");
var middlePart = parts[1];
a source to share
in c #
string url = "www.google.com";
string[] split_strings = url.Split('.');
Console.WriteLine(split_strings[1]);
Get string from textbox:
string url = textbox_url.Text;
string[] split_strings = url.Split('.');
Console.WriteLine(split_strings[1]);
But please use try and catch;)
a source to share
string haystack = "www.google.com"; string needle = "google";
string myWord = GetWordFromString(haystack, needle);
private string GetWordFromString(string haystack, string needle)
{
if (haystack.ToLower().Contains(needle))
{
return needle;
}
}
I am rereading the comment post. I see that you probably don't know which word you are going to extract ... I think the first answer is the one you are looking for.
There are also regular expressions to extract the domain name from the url if that's your specific need. Something like that:
public static string ExtractDomainName(string Url)
{
return System.Text.RegularExpressions.Regex.Replace(
Url,
@"^([a-zA-Z]+:\/\/)?([^\/]+)\/.*?$",
"$2"
);
}
a source to share
Is this as specific as your requirement?
do i need to work only on www.SOMESITE.com
what about other tld extensions like .net, .org, .co.uk, .ie, etc. what about other similar subdomains like www2., api., news. etc ... how about domains without a subdomain like google.com, theregister.co.uk, bit.ly
if it's as simple as your requirement,
then
textBox.Text.Replace("www.", "").Replace(".com", "");
although I have a feeling that you have not thought through or fully explained your requirements.
If this is a more complex scenario, you can take a look at regular expressions.
a source to share