How do you define a "word"? How many words are in the following sentence:
"Isn't it a pity ?"
"Isn't" could be one or two. Are you going to count the question mark? Will it have to handle other languages?
Depending on why you want to do this, the closest approximation might be to simply count the spaces and add one.
Dave.
> How do you define a "word"? How many words are in the
> following sentence:
>
> "Isn't it a pity ?"
>
> "Isn't" could be one or two. Are you going to count
> the question mark? Will it have to handle other
> languages?
>
> Depending on why you want to do this, the closest
> approximation might be to simply count the spaces and
> add one.
>
> Dave.
i don't need it to be fool proof so the spaces plus one would be ok.
would you have the code for that pray tell?
> i don't need it to be fool proof so the spaces plus
> one would be ok.
> would you have the code for that pray tell?
String data = "some text";
int numberOfWords = data.split(" ").length;
/Kaj
> > i don't need it to be fool proof so the spaces
> plus
> > one would be ok.
> > would you have the code for that pray tell?
>
>
> > String data = "some text";
> int numberOfWords = data.split(" ").length;
>
>
> /Kaj
thank you very much. how do i make the String data = JtextArea?
I promise to stop annoying you with my simpleton questions now.
> > How do you define a "word"? How many words are in
> the
> > following sentence:
> >
> > "Isn't it a pity ?"
> >
> > "Isn't" could be one or two. Are you going to
> count
> > the question mark? Will it have to handle other
> > languages?
> >
> > Depending on why you want to do this, the closest
> > approximation might be to simply count the spaces
> and
> > add one.
> >
> > Dave.
>
> i don't need it to be fool proof so the spaces plus
> one would be ok.
> would you have the code for that pray tell?
there are four words in that sentence, its quite basic. "isn't" is one word, how could it possibly be two!? "is not" is two words. a question mark is not a word so thats a stupid question. it won't handle other languages because English is the only one that matters. Rule Brittania
> > thank you very much. how do i make the String data
> =
> > JtextArea?
> > I promise to stop annoying you with my simpleton
> > questions now.
>
> [code]
> String data = textArea.getText();
> /code]
>
> /Kaj
thank you very much for your patience and great assistance
> I actually want to count the number of digits....like
> if user gave
>
> 1320402
>
> it has 7 digits, or 7 chars.
Your definition is incomplete. Determine your expected result if the user provides the following input (for example)t:
1320402
132 0402
1 32 0401
0010 0011
0x00
0x01
0xFF
$12345
123.45
123_45
12!
4*5
a1b2 c3d4
two
twenty-seven
one hundred
-25
555-55-5555
(555) 555-1212
123456
String s = "Hello";
char word [] ;
word = s.toCharArray() // word references an array of five characters
To count the number of character in the Array : int nb = word.length