473,395 Members | 1,941 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

count the words for given file

Hi

i am new to this forum . i am doing small project in that i want to count the number of words in the given .for example in my give file the content will be in this format

Firstname, last name , middle name , address

in this the program is able to count the words in the given file .in this file camma and space in this. the program will able to count the words total 4 not 5 .when program count the space and camma it will give 5 can any one send me code for this program
Dec 28 '07 #1
7 3055
hi thr


i can say is since u want to find
how many words are there in a file
just can use Pattern and Matcher class

like since u want to find alphabets only later no whitespaces

Pattern and Matcher classses or use regex .....................
see API for its methods
Matcher match=Pattern.compile("/w")
match.find()
match.group

may be this helps u too some extent.........


Dhwani:>Its always too soon to quit.
Dec 28 '07 #2
dmjpro
2,476 2GB
Hi

i am new to this forum . i am doing small project in that i want to count the number of words in the given .for example in my give file the content will be in this format

Firstname, last name , middle name , address

in this the program is able to count the words in the given file .in this file camma and space in this. the program will able to count the words total 4 not 5 .when program count the space and camma it will give 5 can any one send me code for this program

Don't ask for any spoon feed code.
First try some code then come here with a particular Probs

Debasis Jana
Dec 28 '07 #3
Check out the stringtokenizer class for a clue on how to split things apart.
Dec 31 '07 #4
dmjpro
2,476 2GB
Check out the stringtokenizer class for a clue on how to split things apart.
Take the String into a StringBuffer then find your specified word and replace it with a different word then again repeat the same process.
The code will be something like this ....

Expand|Select|Wrap|Line Numbers
  1. StringBuffer str_buf = new StringBuffer(file_content);
  2. String specified_word = "abc";
  3. int start_pos;
  4. int count=0;
  5. while(str_buf.toString().indexOf(specified_word)!=-1)
  6. {
  7. str_buf.replace(start_pos,specified_word.length(),""); //just replace it with enpty character
  8. count++;
  9. }
  10.  
Debasis Jana
Dec 31 '07 #5
JosAH
11,448 Expert 8TB
Hi

i am new to this forum . i am doing small project in that i want to count the number of words in the given .for example in my give file the content will be in this format

Firstname, last name , middle name , address

in this the program is able to count the words in the given file .in this file camma and space in this. the program will able to count the words total 4 not 5 .when program count the space and camma it will give 5 can any one send me code for this program
If you want to consider e.g. "first name" as one single word have a look at the API
documentation for the String.split() method. There's no need for tokenizers
nor string buffers at all.

kind regards,

Jos
Dec 31 '07 #6
hi,

im new to java but would like to use the above code to learn how to build a script. the version on my RHEL host is 1.4. can anyone provide a full listing of the script if available?

thanks,
--steve

/opt/openv/java/jre/bin/java -version
java version "1.4.0_04"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0_04-b04)
Java HotSpot(TM) Client VM (build 1.4.0_04-b04, mixed mode)
Jan 3 '08 #7
BigDaddyLH
1,216 Expert 1GB
hi,

im new to java but would like to use the above code to learn how to build a script.
Welcome to TSDN, and welcome to Java.

You need to be clearer: "build a script" isn't meaningful. What are you trying to do? What is your goal?
Jan 3 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: jester.dev | last post by:
Hello, I'm learning Python from Python Bible, and having some problems with this code below. When I run it, I get nothing. It should open the file poem.txt (which exists in the current...
22
by: Ling Lee | last post by:
Hi all. I'm trying to write a program that: 1) Ask me what file I want to count number of lines in, and then counts the lines and writes the answear out. 2) I made the first part like this: ...
9
by: dan | last post by:
this is a program to count average letters per word. i am able to count the total number of letters, but not words. How do you count the total number of words in a text file, so i am able to divide...
11
by: Foodbank | last post by:
Hello, I'm trying to develop a program that will enable me to count the number of words in a text file. As a plus, I'd like to be able to count how many different words there are too. I have a...
9
by: aaron | last post by:
I have a few documents in which I need to get a total word count. Can anyone help? I'd like to create this program so I can get the result after entering the filename, and have the option to...
4
by: writeanand | last post by:
How can I count the frequency of words in a ASCII File using STL? I dont know what words will be found in the file ahead of time. I dont want to use any classes, just a simple program wd do. ...
3
by: waynejr25 | last post by:
can anyone debug my program and get it to run. #include <fstream> #include <iostream> #include <string> #include <cstdlib> #include <map> using namespace std;
4
by: jackloanshark | last post by:
Hello, I am a beginner of c. I wrote a program about counting words in a txt file.But actually there are some error in it and it will stop counting at the first paragraph and just return the number...
3
by: frozz85 | last post by:
I need to search through the file and look for lines that begin with "From". I need to parse the From line and print out the second word for each From line and then also count the number of From...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.