Click here to Skip to main content
15,896,207 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

Notepad Text Line:

#Please Enter The Valid EmailID
#Please Accept(@,_,.)
#Not Allowed(special Cahracter)
nk@gmail.com,nr@gmail.com,ns@gmail.com,sd@gmail.com

The above in Notepad Text file so this notepad text line by line Read (#)Include Text Not Read That line

My Source code in C#
C#
string Emailid = "C:\\MyPath\\EmailId.txt";
       string TextLine = "";
       System.IO.StreamReader objReader;
       objReader = new System.IO.StreamReader(Emailid);
       do
       {
           if (objReader.ReadLine() != "#")
           {
               TextLine = TextLine + objReader.ReadLine();
           }
       } while (objReader.Peek() != -1);
       txtTo.Text = TextLine;
       objReader.Close();


I Want Final Result(TextLine) Notepad Text is
nk@gmail.com,nr@gmail.com,ns@gmail.com,sd@gmail.com
This only
Thanks
Posted
Updated 20-Apr-15 20:41pm
v2
Comments
Tomas Takac 21-Apr-15 2:49am    
And what problem do you have?

Use StartsWith() and Trim():
C#
...
 if (objReader.ReadLine().Trim().StartsWith("#") == false)
...
 
Share this answer
 
This should work just fine. Replace the Console.WriteLine(...) with the appropriate code for what you want to do with the lines of text.

Good luck!

C#
var filePath = "C:\\MyPath\\EmailId.txt";
var fileText = System.IO.File.ReadAllText(filePath);
var lines = fileText.Split(new string[] {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries);

lines = lines.Select(p => p.Trim())
				.Where(p => !string.IsNullOrWhiteSpace(p) &&
				!p.StartsWith("#", StringComparison.OrdinalIgnoreCase))
				.ToArray();

foreach (var line in lines)
	Console.WriteLine(line);
 
Share this answer
 
v8

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900