Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# - Split string by any number of tabs and spaces [duplicate]

Tags:

string

c#

split

Possible Duplicate:
Best way to specify whitespace in a String.Split operation

I am trying to read in the hosts file that contains:

127.0.0.1 localhost
ect...

So as I read it in line by line I need to grab the IP and the host name but how would I grab them if they are formated by any number of tabs or spaces or both.

127.0.0.1<tab><space>localhost
127.0.0.1<space>localhost
127.0.0.1<space><space><space><space>localhost
like image 491
user622469 Avatar asked Jun 21 '12 16:06

user622469


1 Answers

var components = host.Split((char[])null, StringSplitOptions.RemoveEmptyEntries);
like image 182
Branko Dimitrijevic Avatar answered Sep 30 '22 07:09

Branko Dimitrijevic