Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 370569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:01:50+00:00 2026-05-12T14:01:50+00:00

If i got a text file dont run if you cant hide, or you

  • 0

If i got a text file

“dont run if you cant hide, or you will be broken in two strings, your a evil man”

and i want to count how many times the word you is in the text file, and put that value in to a int variable.

how do i go about doing somthing like that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T14:01:50+00:00Added an answer on May 12, 2026 at 2:01 pm

    Assuming there are regular line breaks then if the file is huge this would be less memory intensive than some other approaches here. Uses Jason’s counting method:

            var total = 0;
            using(StreamReader sr=new StreamReader("log.log"))
            {
    
                while (!sr.EndOfStream)
                {
                    var counts = sr
                        .ReadLine()
                        .Split(' ')
                        .GroupBy(s => s)
                        .Select(g => new{Word = g.Key,Count = g.Count()});
                    var wc = counts.SingleOrDefault(c => c.Word == "you");
                    total += (wc == null) ? 0 : wc.Count;
                }
            }
    


    Or, combining the Scoregraphic’s answer here with a IEnumerable method:

        static IEnumerable<string> Lines(string filename)
        {
            using (var sr = new StreamReader(filename))
            {
                while (!sr.EndOfStream)
                {
                    yield return sr.ReadLine();
                }
            }
        }
    

    You could get a nifty one-liner

        Lines("log.log")
            .Select(line => Regex.Matches(line, @"(?i)\byou\b").Count)
            .Sum();
    

    [Edited because System.IO.File now supports enumerating the lines of a file, removing need for hand rolled method of doing the same thing described above]

    Or using framework method File.ReadLines() you could reduce this to:

    File.ReadLines("log.log")
            .Select(line => Regex.Matches(line, @"(?i)\byou\b").Count)
            .Sum();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a multi line text file that I want to use to create
I want Matlab to run some .m file, which writes to a text file.
I have got this text file with latitude and longitude values of different points
this is probably pretty simple, but I've got this text file containing a bunch
I've got the entire contents of a text file (at least a few KB)
I've got a simple application that opens a tab-delimited text file, and inserts that
I' ve got a problem with Haskell. I have text file looking like this:
I've run into a difficult issue with ajax. I've got 2 files. 1 file
hello I've got text file with lines format 1|few ewf ew fewfew I need
I've got a choose file in my AppleScript. When I run the script and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.