• 0

How to count how many times a word appears in a .txt file


Question

11 answers to this question

Recommended Posts

  • 0

Why would you need a program to complete it? Surely the CTRL+F and Count would work better in Notepad++

 

Edit: or what @Nefarious Triggertrigger said :shiftyninja:

  • 0
  On 13/03/2017 at 14:04, fifikaki said:

Nefarious Trigger its a project but i have no idea what to do

Expand  

A school project? Neowin won't do your homework for you, but we can offer you guidance and point you in the right direction.

  • 0
  On 13/03/2017 at 14:12, fifikaki said:

I want to give me just an idea. Νot solve my project...maybe my question it was wrong. sorry

Expand  

I always started with pseudocode before going in to real coding. That way I had an idea of what I wanted to achieve. So let's start with that, what do you want the program to do? If you had to do the job yourself rather than creating a program, how would you count how many times a certain word appears?

  • Like 1
  • 0
  On 13/03/2017 at 14:12, fifikaki said:

 

I want to give me just an idea. Νot solve my project...maybe my question it was wrong. sorry

Expand  

So what self-driven learning have you undertaken so far?  I ask this because what you're asking is ridiculously easy, and I struggle to accept that you've even tried so far.

  • 0
  On 13/03/2017 at 13:43, anonymous_john said:

Hello! Ηow to create a program in C ++ where it counts how many times appears a specific word in a  txt file? Can someone help me?

Expand  

The problem with a question like this is we have no idea what's actually blocking you. Have you ever written any C++? Any program in any language? Do you know how to open a file in C++? Do you know how to compare strings?

 

Show us what you've done and what exactly is blocking you from making progress.

  • 0

 

  On 13/03/2017 at 14:35, winlonghorn said:

I would suggest Regular Expressions. Research MatchCollections with Regular Expressions in .NET. That should allow you to achieve what you want. Hopefully, that points you in the right direction.

Expand  

Yes regex is the solution, if you ever need to parse xml I highly suggest using regex :woot: 

But seriously, don't parse xml with regex, if you want to spend a whole summer debugging code go for it but I wouldn't recommend it, regex isn't designed to work well with nested tags neither is it made to do everything text related even when it could be done with a simpel for loop. Regex is useful as example if you don't want to search for just a word but for all words that start with neo and end with win.

 

He asked about c++ that's quite a bit different from .NET and all of it's libraries available for it.

.NET is like walking with 2 legs but c++ is not even like walking with 1 leg, it's more like having no legs at all in my experience :cry:

  • 0
  On 14/03/2017 at 05:02, Seahorsepip said:

 

Yes regex is the solution, if you ever need to parse xml I highly suggest using regex :woot: 

But seriously, don't parse xml with regex, if you want to spend a whole summer debugging code go for it but I wouldn't recommend it, regex isn't designed to work well with nested tags neither is it made to do everything text related even when it could be done with a simpel for loop. Regex is useful as example if you don't want to search for just a word but for all words that start with neo and end with win.

 

He asked about c++ that's quite a bit different from .NET and all of it's libraries available for it.

.NET is like walking with 2 legs but c++ is not even like walking with 1 leg, it's more like having no legs at all in my experience :cry:

Expand  

Sorry, I was reading in a hurry yesterday. I was trying to help out and work on a project for work at the same time. Probably wasn't the best idea. Thank you for your response! I agree about c++ btw. It can be rough! 

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • PDF Shaper 15.2 by Razvan Serea PDF Shaper is a set of feature-rich PDF software that makes it simple to split, merge, watermark, sign, optimize, convert, encrypt and decrypt your PDF documents, also delete and move pages, extract text and images. The program is optimized for low CPU resource usage and operates in batch mode, allowing users to process multiple PDF files while doing other work on their computers. PDF Shaper is available in three editions - Free, Premium and Ultimate. Compare and pick edition which is suitable for you. Compatible with Windows 7, 8, 10, 11. Features: Extract text, images of other objects from single or multiple PDFs Convert PDF to Word RTF or image, or convert image to PDF Extract pages from PDF and save them as separate PDF files Combine several PDF files into single PDF Encrypt and decrypt PDF with password, set user permissions Rotate, crop and normalize pages, set meta data Add watermark or remove images from PDF Benefits: Easy-to-use, intuitive user interface Low CPU resource usage during any process, including conversion Free for personal use and for any non-commercial organization Supports Unicode characters Supports batch processing for any operation Small installation size PDF Shaper 15.2 changelog: Updated translations. Improved table positioning for better layout accuracy (DOC to PDF). Enhanced image resizing to more accurately reflect DPI settings (Image to PDF). Improved text positioning for consistent formatting (TXT to PDF). Optimized overall performance on 64-bit systems. Enhanced support for Unicode text documents. Fixed an issue where font settings were not applied correctly to text files Download: PDF Shaper 15.2 | 7.9 MB (Free for personal use only) Link: PDF Shaper Home Page | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • I kind of do not engage much with people whose first retort is an ad hominem. Nevertheless the data is there.
    • I don't know if this is helpful or not, but just something I have an opinion on... Gaming PC builds where you've specced up the parts you want, built the system, colour matched things, etc... They may well be a labour of love, but on the 2nd hand market - nobody cares.  People are looking for deals, not your passion project
    • Firefox 139.0.4 fixes browser freezes, wallpaper bugs on Windows, and more by Taras Buria Mozilla is rolling out a new update for Firefox 139. Version 139.0.4 arrived today with four fixes and security patches. With today's release, Mozilla fixes freezes that occur when switching between apps or opening certain parts of the browser, issues with drop-down menus and triple-clicking text, and a bug with incorrect file names when setting a picture as the desktop background on Windows (the image would save as a BMP file with a blank name instead of Desktop Background.bmp) Here is the changelog: Security updates in Firefox 139.0.4 include two patches for vulnerabilities of high impact: CVE-2025-49709: Memory Corruption in canvas surfaces. Certain canvas operations could have led to memory corruption. CVE-2025-49710: Integer overflow in OrderedHashTable. An integer overflow was present in OrderedHashTable used by the JavaScript engine. As usual, you can update Firefox by heading to Menu > Help > About Firefox. Alternatively, grab the browser from the official website, Microsoft Store (if you are on Windows 10 and 11), or Neowin's Software page. For reference, release notes for version 139 and its subsequent bug-fixing update, 139.0.1, are available here and here. In other Firefox news, Mozilla recently announced the end of Pocket, Fakespot, and some other services. The company says its goal is to consolidate efforts and focus on Firefox development, its primary product.
  • Recent Achievements

    • Reacting Well
      Alan- earned a badge
      Reacting Well
    • Week One Done
      IAMFLUXX earned a badge
      Week One Done
    • One Month Later
      Æhund earned a badge
      One Month Later
    • One Month Later
      CoolRaoul earned a badge
      One Month Later
    • First Post
      Kurotama earned a badge
      First Post
  • Popular Contributors

    1. 1
      +primortal
      494
    2. 2
      ATLien_0
      267
    3. 3
      +FloatingFatMan
      225
    4. 4
      +Edouard
      199
    5. 5
      snowy owl
      141
  • Tell a friend

    Love Neowin? Tell a friend!