how to ignore blank lines

Posted by Oswaldlily under C# on 11/22/2011 | Points: 10 | Views : 2376 | Status : [Member] | Replies : 1
I have line by line row in this string s
string[] s=/* line by line code */

in this s,if it finds blank line,it should ignore it..
how is it possible




Responses

Posted by: Dnandha87 on: 11/24/2011 [Member] Starter | Points: 25

Up
0
Down
public void RemoveBlanks()
{
string [] s = new string[100];
string[] s1 = new string[100];
s = File.ReadAllLines(@"pathname\sample.txt");
List<string> list = new List<string>(s);
int i= 0;
foreach (string item in list)
{
if (item != "")
{
s1[i] = item;
i = i+1 ;
}
}
File.WriteAllLines(@"pathname\sample.txt", s1);
}



Now the array s1 contains the data without blankline and sample.txt file also......



Regards
Nandha Kumar,

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response