Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to read a text after "Email:" via stream reader without looping ...Is there any easy method to get it fast as i am checking large number of files at a time....
C#
StreamReader reader = new StreamReader(Target1);
            string line = string.Empty;

            var matches1 = Regex.Match('Email', ('^.*')).Groups[1].Value;
            while ((line = reader.ReadToEnd().ToLower()) != null)
            {
                if (line.Contains('email'))
                {
                    string[] crefids3 = line.Split(':');
                    for (int mj = 0; mj < crefids3.Length; mj++)
                    {
                        randomName = crefids3[1].ToString();
                    }
                }
            }
            reader.Close();
Posted
Updated 14-Nov-21 2:24am
v3
Comments
Sergey Alexandrovich Kryukov 3-Feb-13 20:38pm    
If you ask "how to do something", don't say "without this or that", because it may make no sense. Or at least explain it...
—SA

Depends on what you mean by "large". But if you really mean very large amounts then in general the answer is no. You might be able to increase the buffer size but that depends on the actual stream.

With care you might find that if you parse it first then process it you might get better performance (right now it looks like you are processing it once found.)

You might also examine your need to make it faster - specifically is this a business requirement or just something you think is ideal?
 
Share this answer
 
Use

break;

before closing If condition.
 
Share this answer
 

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