How i can count the number of words in a string?
hi, i want to know how to count the number of words in a string
e.g. java is a very powerful computer language.
i will get 7 words.
thanks in advance..
Jverd, this has actually been answered, but due to an
attack of goldie-itis, all the answers were hosed.
The OP did get an answer, though.Yeah, I know. I just didn't know if he saw the answer before it went away.
Similar Messages
-
How do I count the number of *'s in a string?
I need to count the number of * in a string of carakters. And the return the number. 0 for no *'s in the string 2 for two *'s in the string and so on.
It's probably quite simple but I can't figure out how!Like this.
james_t_dk wrote in message
news:[email protected]..
> I need to count the number of * in a string of carakters. And the
> return the number. 0 for no *'s in the string 2 for two *'s in the
> string and so on.
>
> It's probably quite simple but I can't figure out how!
[Attachment Untitled 10.vi, see below]
Attachments:
Untitled_10.vi 18 KB -
How do I count the number of occurrences of a string within a group of cells?
Hello all, I'm trying to figure out how to count the number of times a child has completed certain tasks. Here is a sample of the data (it is highly simplified here, but contains what I hope is needed to answer my question):
Unnamed Table
Objective
John
Ann
Alex
Dave
Eric
20a 20b 20c
x
20a 20b 20c
x
20a 20b 20c
x
x
19b 20a
x
x
20c 21b 22
x
What I am trying to do is count the number of times each child completed each objective - but I can't figure out how to go about splicing up the "objectives" fields for counting while still being able to compare them to whether or not the "child" has 'an x in the box' in that particular row.If I read your example correctly, John's counts should be 2 for 20a, 1 for 19b, 20b and 20c, and 0 for any other objectives listed.
Here's an example that will work for your data set, assuming that any objective ma occur only once in each row of column A of the Main table. I've added an a to objective 22, but I think it is unnecessary, provided there is no objective 122, 221, etc.
This uses a two step process.
The table AUX extracts the objectives completed by each student, using the checkboxes in Main. Note that it also adds a space at the beginning and end of each string. This provides an extra character before the first objective code and after the last objective code in that row, used by the wildcard specification in the formula in the Summary table.
Formula:
Aux::B2: =IF(OFFSET(Data :: $A$1,ROW()-1,COLUMN()-1)," "&OFFSET(Data :: $A$1,ROW()-1,0)&" ","")
Fill right to the last column and down to the last row of Aux.
Summary uses COUNTIF to count the number of occurrences of each of the objectives listed in column A of that table.
Formula:
Summary::B2: =COUNTIF(Aux :: B,"=*"&$A2&"*")
Fill right and down as the previous formula.
Regards,
Barry -
How do I count the number of records returned in the CMIS query
How do I count the number of records returned in the query CMIS?
SELECT COUNT(*) FROM ora:t:IDC:GlobalProfile WHERE ora:p:xRegionDefinition = \'RD_PROJETOS_EXCLUSIVOS\''}
Euler HomeroHi Euler,
interestingly enough, the reference guide for CMIS ( http://wiki.alfresco.com/wiki/CMIS_Query_Language ) that I found does not mention the COUNT function at all. On the other hand it states that: "The SELECT clause identifies which virtual columns to return in the result set. It can be either a comma-separated list of one or more queryNames of properties that are defined by queryable object types or * for all virtual columns."
There are, however, some other posts like e.g. http://alfrescoshare.wordpress.com/2010/01/20/count-the-total-number-of-documents-in-alfresco-using-sql/ which state that they could make it working.
Having asked in the WebCenter Portal forum, I assume that your content repository is WebCenter Content. The CMIS doc for the Content is available here: http://docs.oracle.com/cd/E23943_01/doc.1111/e15813.pdf (no COUNT there either). It does, however, mention explicitly that "CMIS queries return a Result Set where each Entry object will contain only the properties that were specified in the query.". This means your could rather investigate the Result Set. Note that there are also other means than CMIS how to get the requested result set (e.g. calling a search service directly via so-called RIDC).
In the given context I am also interested what your use case is. OOTB CMIS in WebCenter Portal is used, for instance, in Content Presenter, where it is content rather than "parameters" what's displayed. -
How can we send only one message to a WCF service at a time? How we can limit the number of concurrent calls to a WCF service without use the Singleton pattern or without do the change in BizTalk Configuration file? Can we do it by Host throttling?
Hi Pawan,
You need to use WCF-Custom adapter and add the ServiceThrottlingBehavior service behavior to a WCF-Custom Locations.
ServiceThrottlingBehavior.MaxConcurrentCalls - Gets or sets a value that specifies the maximum number of messages actively processing across a ServiceHost. The MaxConcurrentCalls property specifies the maximum number of messages actively
processing across a ServiceHost object. Each channel can have one pending message that does not count against the value of MaxConcurrentCalls until WCF begins to process it.
Follow MSDN-
http://msdn.microsoft.com/en-us/library/ee377035%28BTS.10%29.aspx
http://msdn.microsoft.com/en-us/library/system.servicemodel.description.servicethrottlingbehavior.maxconcurrentcalls.aspx
I hope this helps.
Rachit
If this answers your question please mark it accordingly. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply. -
Help!! count the number of words in one line
the question is that use JOptionPane and Array to count the number of words and characters that user inputed.
for example, if I enter the " this is a java program"
that messages have display 5 and 18.
please show me the a completely program.
thx!!!!You guys are heartless. Even you weren't born with programming knowledge hard-coded into your brain. Even you had to start from zero. Even you had to struggle at something in your life. In this spirit, I think that we should give this poor student a break and try to help him as much as possible. Here, try out my program, and perhaps it will give you some ideas for your own:
public class WordCountingHomework
public static void main(String[] args) throws InterruptedException
String input = JOptionPane.showInputDialog("Please enter a String");
// get your String and split the String into words
// This will allow you to count words easily
String[] strArray = new String(wordCountByteArray).split(" ");
int delay = 400;
for (;;)
// loop through the array to count the words
for (String string : strArray)
System.out.print(string + " ");
Thread.sleep(delay);
System.out.println();
delay *= 7;
delay /= 10;
private static byte[] wordCountByteArray =
0x50, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x20, 0x64, 0x6f, 0x20, 0x79, 0x6f,
0x75, 0x72, 0x20, 0x6f, 0x77, 0x6e, 0x20, 0x66, 0x61, 0x72, 0x6b, 0x69,
0x6e, 0x27, 0x20, 0x68, 0x6f, 0x6d, 0x65, 0x77, 0x6f, 0x72, 0x6b, 0x21
} -
Count the number of occurrence in a string
is there any api for counting the number of occurrence in a string or should i write a method myself?
for example. I want to count "." in "1.2.3.4.". i want to count the dot in this string.
I am just wondering.
Thanks in advance.is there any api for counting the number of
occurrence in a string or should i write a method
myself?The latter. -
Which method to count the number of character in a string?
Hi all,
I want to know which class and method to count the number of character in a string?
Garyhttp://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html
-
How count the number of substrings in a string
Hi all,
I wonder if someone can help me and point out where I'm going wrong.
I want to count the number of substring starting with 'd' and ending with 'e' in a string supplied by a user.
currently my code is only counting the number of 'd' and 'e' characters in the string.
public static void main (String [] args)
Scanner input = new Scanner (System.in);
String mstring;// string variable that the user will enter
int i = 0; // upstep variable
int count = 0; // int variable to count the number of substrings
System.out.print("Enter a string: ");
mstring = input.nextLine();
while (i != mstring.length())
if(mstring.charAt(i)=='d'){count++;}
else if (mstring.charAt(i)=='e'){count++;}
i++;
System.out.println("The total d e substrings is " + count);
}For example if the user enters adbedeaadffe the total number of substrings should be 5 but I'm getting 6 as the program is just counting the number of times it comes across 'd' and 'e'
Can anyone shed some light on this for me thanks.Hi all I had a good few replies to this question but they seem to have been removed from the system for some reason.
I've changed my code slightly and it works but only for one round of the guard.
Scanner input = new Scanner (System.in)
String mstring;// main string variable that the user will enter
int i = 0; // upstep variable
int count = 0; // int variable to count the number of substrings
System.out.print("Enter a string: ");
mstring = input.nextLine();
int y =mstring.length();
while (i != mstring.length() && y !=0)
if (mstring.charAt(i) == 'd' && mstring.charAt(y-1)=='e'){count = count+1;}
y--;
i++;
System.out.println("The total a b substrings is " + (count));The above code will only print out one substring of adbedeaadffe but that is not what I need, I need to be able to print out all of the substrings.
Can anyone tell me where I'm going wrong.
Thanks in advance -
How do I count the number of cells with a particular text in it?
I have a column with peoples name in each cell. I want to count the numbe rof times a persons name appears in the column. How do I do this? any help would be great ! thanks in advance.
Hi Evilhomer,
The function COUNTIF will do this. Here are two Tables on one sheet. Table 1 contains names in Column B.
Table 2 contains the names once only (in any order) in Column A, with a COUNTIF formula in Column B to count how many times a name occurs in Table 1.
The formula in Sheet 2, Cell B2 is:
=COUNTIF(Table 1 :: B2:B5,A2)
Enter the formula in B2 then copy down.
It is easier to create the two tables on one sheet. If you then want to move a table to another sheet, Numbers will convert the formulas to keep the references valid.
There are other ways to do what you want. Please reply if this is not what you want.
Regards,
Ian. -
Calling a file and counting the number of words in it-please help!!
* @(#)WordCounterTwo.java
* WordCounterTwo application
* @author
* @version 1.00 2007/11/17
import java.util.Scanner;
public class WordCounterTwo {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
String fileName;
int countWords;
System.out.println("Please enter the name of the file: ");
fileName = keyboard.nextLine();
System.out.println(countWords.lastIndexOf());
}I am getting error message as follows:
cannot find symbol constructor StringTokenizer() on line
I am asking the user to enter the name of a file, and the output is supposed to display the number of words in the file that chosen. I'm not sure if I am going about this right way, and not sure why I am getting the erorr messages.
* @(#)WordCounter.java
* WordCounter application
* @author
* @version 1.00 2007/11/17
import java.util.Scanner;
import java.util.StringTokenizer;
public class WordCounter {
public static void main(String[] args) {
String sentence;
Scanner keyboard = new Scanner(System.in);
StringTokenizer words = new StringTokenizer(); //line 17
int numberWords;
System.out.println("Please enter a sentence");
sentence = keyboard.nextLine();
sentence = words.nextToken();
while (words.hasMoreTokens())
numberWords++;
System.out.println(numberWords);
} -
A quick way to count the number of newlines '/n' in string of 200 chars
I am trying to establish the number of lines that a string will generate.
I can do this by counting the number of '/n' in the string. However my brute force method (shown below) is very slow.
Normally this would not be a problem on a 2800mhz Athlon (Standard) PC this takes < 1 second. However this code resides within a speed critical loop (not shown). The code shown below is a Achilles heal as far as the performance of this speed critical loop goes.
Can anyone suggest a faster way to count the number of �/n� (new lines) within a text string of around 50- 1000 chars, given that there may be 10 � 100 newline chars. Speed is a very important factor for this part of my program.
Thanks in advance
Andrew.
int lineCount =0;
String txt = this.getText();
//loop throught text and count the carridge returns
for (int i = 0; i < txt.length(); i++)
char ch = txt.charAt(i);
if (ch == '\n')
lineCount ++;
}//end forMessage was edited by:
scottie_uk
Message was edited by:
scottie_ukWell, here is a C version. On my computer the Java version (reply 9 above) is slightly faster than C. YMMV. For stuff like this a compiler can be hard to beat even with assembler, as you need to do manual loop unrolling and method inlining which turn assembly into a maintenance nightmare.
// gcc -O6 -fomit-frame-pointer -funroll-loops -finline -o newlines.exe newlines.c
#include <stdio.h>
#include <string.h>
#if defined(__GNUC__) || defined(__unix__)
#include <time.h>
#include <sys/time.h>
#else
#include <windows.h>
#endif
#if defined(__GNUC__) || defined(__unix__)
typedef struct timeval TIMESTAMP;
void currentTime(struct timeval *time)
gettimeofday(time, NULL);
int milliseconds(struct timeval *start, struct timeval *end)
int usec = (end->tv_sec - start->tv_sec) * 1000000 +
end->tv_usec - start->tv_usec;
return (usec + 500) / 1000;
#else
typedef FILETIME TIMESTAMP;
void currentTime(FILETIME *time)
GetSystemTimeAsFileTime(time);
int milliseconds(FILETIME *start, FILETIME *end)
int usec = (end->dwHighDateTime - start->dwHighDateTime) * 1000000L +
end->dwLowDateTime - start->dwLowDateTime;
return (usec + 500) / 1000;
#endif
static int count(register char *txt)
register int count = 0;
register int c;
while (c = *txt++)
if (c == '\n')
count++;
return count;
static void doit(char *str)
TIMESTAMP start, end;
long time;
register int n;
int total = 0;
currentTime(&start);
for (n = 0; n < 1000000; n++)
total += count(str);
currentTime(&end);
time = milliseconds(&start, &end);
total *= 4;
printf("time %ld, total %d\n", time, total);
fflush(stdout);
int main(int argc, char **argv)
char buf[1024];
int n;
for (n = 0; n < 256 / 4; n++)
strcat(buf, "abc\n");
for (n = 0; n < 5; n++)
doit(buf);
} -
How do I count the number of times a word appears in a column?
What I have is a spreadsheet logging work history. Let's say the work location is "office", "home", or "travel" and I want to have a separate cell in another table for totals, count up the number of time each appears in the data for the year. So it would look like this:
Date
Location
sept 1
office
sept 2
home
sept 3
home
sept 4
travel
sept 5
office
sept 6
office
sept 7
office
sept 8
travel
sept 9
home
sept 10
office
Totals
Days
10
Office
5
Home
3
Travel
2
I just can't figure out how to develop the formula to put in the Totals column to make it work this way. If you can help me achieve this I'd really appreciate it!Hi SpartanAntarctican,
Table 1 to record your locations
Date
Location
sept 1
office
sept 2
home
sept 3
home
sept 4
travel
sept 5
office
sept 6
office
sept 7
office
sept 8
travel
sept 9
home
sept 10
office
Table 2 to sum your locations
Totals
Days
10
Office
5
Home
3
Travel
2
In Table 2 the formula in B2
=ROWS(Table 1::A)−1
Minus 1 because there is a Header Row in Table 1.
In Table 2 the formula in B3 (and Fill Down)
=COUNTIF(Table 1::B,A3)
You can check this by adding 5 + 3 + 2 to arrive at 10
Or maybe delete Row 2 put the Days calculation into a Footer Row in Table 2
=SUM(B) .
Regards,
Ian. -
How do I count the number of unread emails in WebCenter ?
how can I show unread emails counter on webcenter spaces ( I used the default WC Mail task flow )
Hi Euler,
interestingly enough, the reference guide for CMIS ( http://wiki.alfresco.com/wiki/CMIS_Query_Language ) that I found does not mention the COUNT function at all. On the other hand it states that: "The SELECT clause identifies which virtual columns to return in the result set. It can be either a comma-separated list of one or more queryNames of properties that are defined by queryable object types or * for all virtual columns."
There are, however, some other posts like e.g. http://alfrescoshare.wordpress.com/2010/01/20/count-the-total-number-of-documents-in-alfresco-using-sql/ which state that they could make it working.
Having asked in the WebCenter Portal forum, I assume that your content repository is WebCenter Content. The CMIS doc for the Content is available here: http://docs.oracle.com/cd/E23943_01/doc.1111/e15813.pdf (no COUNT there either). It does, however, mention explicitly that "CMIS queries return a Result Set where each Entry object will contain only the properties that were specified in the query.". This means your could rather investigate the Result Set. Note that there are also other means than CMIS how to get the requested result set (e.g. calling a search service directly via so-called RIDC).
In the given context I am also interested what your use case is. OOTB CMIS in WebCenter Portal is used, for instance, in Content Presenter, where it is content rather than "parameters" what's displayed. -
How do I display the number of words I've written in the new Pages update?
I just downloaded Mavericks and updated pages and I can't figure out how to display the amount of words I have written. It used to automatically be at the bottom of the page.
Toolbar > View > Word Count
Peter
Maybe you are looking for
-
Can you move content from one Creative to anoth
hi, i just got the creative zen 40g mp3 player and i already have a fully loaded 5g Creative Zen micro. is there an easy way to take what is loaded in the 5g and move it to the 40g or do i have to start from scratch? thanks anyone
-
Get the Change history of a Purchase order
Hi Gurus, We have custom workflow which will send a mail to the user when he creates a new PO using Me21n. Our requirement is to send a mail to the user when he add a new line item to the existing PO. The big question is How to find a new line item a
-
How to get the Version of the Solution Manager
Hi Experts, The Solution Manager is Already Insatlled on our Machine. How to Find out the Version of the Solution Manager??? How to Disply the Solution Manager Key???? Please give me the Proper Solution on this. Regards Khanna
-
No floppy diskette driver in Windows 10 Preview Enteprise ISO x64?
I am using .VFD floppy diskette to plug autounattend.xml into ISO installs in order to automate VM provisioning. And now, there is no flpydisk.sys. How come? I know the Generation 2 machines do not support VFD, yet I am using the normal Generation 1
-
What are all the components and attrubutes of the SAP script
hi what are all the components and attrubutes of the SAP script please reply thanks in advance