Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# string split

Tags:

string

c#

split

I have a string = "google.com 220 USD 3d 19h".

I want to extract just the ".com" part.......

whats the easiest way to manipulate the split string method to get this result?

like image 619
Goober Avatar asked Jun 23 '09 17:06

Goober


2 Answers

I'm guessing you either want to extract the domain name or the TLD part of the string. This should do the job:

var str = "google.com 220 USD 3d 19h";
var domain = str.Split(' ')[0];           // google.com
var tld = domain.Substring(domain.IndexOf('.')) // .com
like image 110
Noldorin Avatar answered Oct 04 '22 22:10

Noldorin


Alternate idea

string str = "google.com 220 USD 3d 19h";
string match = ".com";
string dotcomportion = str.Substring(str.IndexOf(match), match.Length);
like image 44
Cody C Avatar answered Oct 04 '22 22:10

Cody C