How to count words in a text ?

Hi all,
can anyone show me how to count the number of words in a text.
thank in advandce,
Toan.

Hi,
Are you reading the text from a file or is it stored in a string buffer?
The best way would be to use a StringTokenizer assuming that all your words are separated by a space ' ' you could use that as your delimiter.
Something like..
String text = "This is just a bunch of text stored as a string.";
StringTokenizer words = new StringTokenizer( text, " ", false );
int numberOfWords = words.countTokens();I hope that helps,
.kim

Similar Messages

  • How to count the number of text boxes that are data entered

    How to count the number of text boxes that are data entered in visual basic form.

    Here is an Iterator that expands on my previous response:
    ''' <summary>
    ''' Iterator for form controls
    ''' </summary>
    ''' <param name="onlyControlsOfType">specify type if a certain type of controls needed</param>
    ''' <param name="onlyTopLevel">if true don't search containers within the form</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Iterator Function AllControls(Optional onlyControlsOfType As Type = Nothing, _
    Optional onlyTopLevel As Boolean = False) As IEnumerable(Of Control)
    Dim ctrl As Control = Me.GetNextControl(Me, True)
    Do Until ctrl Is Nothing
    If onlyControlsOfType Is Nothing OrElse ctrl.GetType = onlyControlsOfType Then
    If TypeOf ctrl.Parent Is Form OrElse Not onlyTopLevel Then
    Yield ctrl
    End If
    End If
    ctrl = Me.GetNextControl(ctrl, True)
    Loop
    End Function
    Some sample uses:
    For Each
    For Each c As Control In AllControls()
    Debug.WriteLine(c.Name)
    Next
    List of all controls, including controls in containers i.e. Groupbox
    Dim l As List(Of Control) = AllControls().ToList
    List of all Textbox controls, including Textboxes in containers i.e. Groupbox
    l = AllControls(GetType(TextBox)).ToList
    List of all Textbox controls, don't include Textboxes in containers i.e. Groupbox
    l = AllControls(GetType(TextBox), True).ToList
    'Those who use Application.DoEvents() have no idea what it does and those who know what it does never use it.'  JohnWein
    Multics
    My Serial Port Answer

  • Counting words in a text widget

    Hi,
    Is there a way I can count the number of words in a text box widget?  I realise that means counting the number of words in the attached variable - but can I do this?
    I have tried playing with Javascript (about which I know nothing)
    I put the script below into the script window for a button, but nothing seems to happen!
    Test=Q5WidgetAnswer.split(" ").length-1;
    document.write(Test);
    I want to check for three words in an answer and if there are only two, or four, warn that there are Three answers.
    Would be grateful for any help!

    After much heartache I solved the issue. 
    The code needed to be as follows:
    var objCP = document.Captivate;
    var Answer = objCP.cpEIGetValue('WidgetAnswer');
    var Words;
    if(Answer ==  ''){   /* tests for empty answer */
      Words=0;
    alert("Fred")
    else {
    Words = Answer.replace(/[^ ]/g,'').length+1;    /* counts the number of spaces in answer */
    Where objCP can be any name you want, and cpEISetValue and cpEIGetValue are special Captivate functions
    /* and */ enclose a comment

  • How to count words in a PDF file?

    Is there any way I can count words in a PDF file without resorting to Acrobat Reader (which apparently has that feature)?
    That's a massive program, which I actually don't like.
    I need to count words in the PDF file because I write my papers with LaTeX, and they're full of my extensive comments.
    Do you know of any alternative?

    that utility IIRC cannot be found on xpdf (the official Archlinux package) anymore and its part of poppler
    edit: its pdftotext btw
    Last edited by dolby (2008-05-11 13:35:05)

  • How to count words?

    Hello, namless hero~
    Just like the title said, if you has any idear, please reply this post, thanks!!

    There are two basic ways I can think of to do this. Either get the text, and run your own word count alogorithm on it, or use the word boundary methods in ParagraphElement. In the first instance, you have more control over what is considered as a word, and in the second way you let the Player decide.
    Option 1:
    You can get the text of the TextFlow by exporting using the plain text filter:
         var text:String = TextFilter.export(textFlow, PLAIN_TEXT_FORMAT, ConversionType.STRING_TYPE) as String;
    Once you have the text, just scan through it to find the words. This is the best way if you want to define for yourself what constitutes a word.
    If there is going to be a lot of text, you may prefer to look at it paragraph by paragraph. So instead you would loop through the paragraphs in the flow, and call getText() on each one, and then run your algorithimn on the String returned by getText().
    Option 2:
    Otherwise, you could iterate through the paragraphs of the flow, looking for word boundaries. This will get you all possible word boundaries, including between spaces. To do this, it would look something like this:
         var paragraph:ParagraphElement = textFlow.getFirstLeaf().getParagraph();
         do {
              var relativePosition:int = paragraph.findWordBoundary(0);
              while (relativePosition < paragraph.textLength)
                   trace("Word boundary at", paragraph.getAbsoluteStart() + relativePosition);
                   relativePosition = paragraph.findWordBoundary(relativePosition);
              paragraph = paragraph.getNextParagraph();
         } while (paragraph != null);
    I haven't compiled this or debugged it, and I coded it from memory, but hopefully this will serve as a guideline for what you could do.

  • How to split words alone from text ?

    how to split the text from a text file even with out the special characters to be stored to DB.I have seperated words using split.but it is having special charecters. is there any option with split to give special characters too as delimiters (i mean multilple delimiters).
    Or any other way to get the words and integers alone?

    gs_ravishankar wrote:
    i think his problem is he has a file which has some text row wise, this text contains different special characters.
    and his job is to read the text from the file and remove all special characters in the text and store this string in DB.
    if this is the case,
    i would suggest to get the ascii value range of all special characters and then write a condition for it.
    may be something like this
    if(text.chatAt(i) >= 12 && text.charAt(i) <= 45)
    text.replace();Jeebus, have you ever heard of regular expressions?

  • How to make words in a text field change color in play mode by clicking on them?

    I have a text field on a slide, wanting to change the color of certain words randomly by clicking on them in play mode. I dont know what word in what order will be mentioned by the audience, so I can not set a fixed order in advance.
    Any help is appreciated.
    Thanks a lot.

    create a slide with all the text boxes in place
    duplicate the slide as many times as you have text boxes you want to change colour
    on the second slide, change the colour of one of the text boxes as required
    on the first slide, select one of the text boxes
    open the inspector:     Inspector > Hyperlink >
               enable as hyperlink > link to slide > click slide button > select the correct slide from the drop down menu
    in play mode, clicking on the hyperlink will display the appropriate slide with that text changing colour
    repeate the process for each text box

  • How to count frequency of specific text in Column?

    Hi All,
    We have  an FR , designed in FR studio which when run, pulls from hfm the " Calculation Status" of all the entities in a text column.  The Status come as "OK", "SC","CN" ,"CH"etc. see below exmple:
    Entity                              Status
    C1                                   CH
    C2                                   SC
    C3                                   CN
    C4                                   CH
    Now If i am trying to apply some formula to calculate the number of times "CH" is coming in that column, its not getting possible.
    Somebody please suggest whether such functionality exist in FR or not. If yes, how can i achieve this.
    Thanks in advance for always help!

    Hi All,
    We have  an FR , designed in FR studio which when run, pulls from hfm the " Calculation Status" of all the entities in a text column.  The Status come as "OK", "SC","CN" ,"CH"etc. see below exmple:
    Entity                              Status
    C1                                   CH
    C2                                   SC
    C3                                   CN
    C4                                   CH
    Now If i am trying to apply some formula to calculate the number of times "CH" is coming in that column, its not getting possible.
    Somebody please suggest whether such functionality exist in FR or not. If yes, how can i achieve this.
    Thanks in advance for always help!

  • How to Count total number of Words in PDF?

    I am used Adobe Acrobat javascript inbuilt function getPageNumWords(<pagenumber>) it return the number of words present in specified page, but while am copy and paste text content from PDF file to MS Word, Words count given by MS Word is little bit differ, so any one know in which aspect Acrobat count the words?
    Which words count result is correct?
    Shall is go with Acrobat Words count result or MS Words count result?
    But I want to count the total number of words in PDF file (my input is PDF file) else can I go with iText?
    Words count in PDf using iText is possible?

    Word counts are likely to vary a little according to how you count. For instance, are hyphenated words one or two words? What if the hyphen is at the end of a line? Do numbers count as words? Headers and footers? Captions?
    Generally, you just accept a slight variation. If you are counting words in a professional context, i.e. where payment is per word, you probably need a contractual definition of how words are to be counted; in the absence of one, I suggest you use Word.

  • How in Flash CS4 to change text words of .fla file from a website template?

    I have a website template in which I am trying to change the header text words and menu text words to customize the template. How do I do this in Flash CS4? Thanks!

    There are any number of ways these text elements might have been designed into the file.  So you pretty much have to search for things.  If you do not see the text that you want to change when you open the fla file, then you may need to either make some layers visible that are not (eyeball icon next to layer name) or you may need to look into the actionscript code to see if the text is being dynamically written when the file opens.  If you happened to receive any .as, .txt, or .xml files with the template, the text elements may also be defined in those files.
    Just so you know, and this is just an observation, it appears from experience in these forums that template designers tend to make templates so that you are more likely to hire them to update things than to be able to solve it yourself.

  • How can I digitalize a document text in PDF and export it to WORD?

    Anthony
    How can I digitalize a document text in PDF and export it to WORD?

    If you already have a PDF document, ExportPDF can help you with this task. https://www.acrobat.com/exportpdf/en/convert-pdf-to-word.html
    On the other hand, if you have a physical document, you'll need to scan it into a PDF document first.
    Depending on what you need to do you may require different tools & services, so please help us out with more details.
    Vlad

  • How to set to bold a single word in the text box?

    How can I set to bold a single word in the text box? When I try, it puts the whole text bold.

    you should do this by HTML way
    like this :
    sym.$("your text box Name").html("Hello i'm <strong>Bold</strong> one")
    Zaxist

  • How do I copy and paste text from a converted Word document?

    I just converted a pdf file into word.  I want to copy and paste the informatiuon into another document.  How do I do that?

    Hi Sara.  Tanks for responding.  If I cannot figure this out (I  was up
    until 2am last night), I want to cancel my subscription.
    Here are two files you can check on/help me with.  When I try again,  it
    comes up 'an error has occurred when trying to access the service.'
    Please advise.
    Pat Tomassi
    In a message dated 11/1/2014 12:55:23 A.M. Eastern Daylight Time, 
    [email protected] writes:
    How  do I copy and paste text from a converted Word document?
    created by Sara.Forsberg (https://forums.adobe.com/people/Sara.Forsberg) 
    in Adobe Acrobat.com Services - View the full  discussion
    (https://forums.adobe.com/message/6888908#6888908)

  • How do I cut and paste text from a Word doc to my yahoo email?

    I am suddenly unable to cut and paste from a Word document into the body of my yahoo email. I never had this problem before, but recently trying to paste my resume into the site 4entertainmentjobs.com, I ran into trouble. I followed your instructions and found my profile folder, but there was no user.js file in there. I created one in text edit and replaced mozilla.org with 4entertainmentjobs.com, but it still didn't work. Today I tried to go back and put Mozilla back in, but I still cannot get it to work. Then I downloaded your add-on "allow clipboard". That did not work either.

    Hi Sara.  Tanks for responding.  If I cannot figure this out (I  was up
    until 2am last night), I want to cancel my subscription.
    Here are two files you can check on/help me with.  When I try again,  it
    comes up 'an error has occurred when trying to access the service.'
    Please advise.
    Pat Tomassi
    In a message dated 11/1/2014 12:55:23 A.M. Eastern Daylight Time, 
    [email protected] writes:
    How  do I copy and paste text from a converted Word document?
    created by Sara.Forsberg (https://forums.adobe.com/people/Sara.Forsberg) 
    in Adobe Acrobat.com Services - View the full  discussion
    (https://forums.adobe.com/message/6888908#6888908)

  • How can I copy and paste text into Word in Acrobat 9 Pro

    How can I copy and paste text into Word from Acrobat 9 Pro?

    You might find it easier to export the file to Word under File > Export > Word in Acrobat 9.

Maybe you are looking for

  • Header and Footer in Block ALV Display

    Hi All, My requirement includes to ALV Block List Display with header and footer. I have made two forms TOP_OF_PAGE and END_OF_PAGE . I have pass the form and name of event to an internal table it_events. This it_events[] is then passed to FM ' REUSE

  • Characteristic Update

    Hi experts, The SAP module which I work on is DMS u2013 Document Management System. 1)     We use u2018Classificationu2019 to classify the document. 2)     For documents we use the class of type 017. This class will have u2018characteristicsu2019 (ct

  • Premiere Pro CS5 and After Effects CS5 crash after splash screen

    Im am fed up with this ive done everything i can and no one seems to know whats wrong, i installed CS5 on my macbook and imac i7, and they both worked for a while but then suddenly my imac i7 cs5 stopped working and kept crashing, my macbook continue

  • Bc4j oc4j No home wrapper specified for  error

    I have deployed some business component about 25 of them some business component gives the error no home wrapper specified error the application works fine but this is shown when i start the server can any one tell me the reason why this happens and

  • Compiling problem related to library conflict

    Hi everybody, As I used JDeveloper 10.1.3.0.3 to compile my program, I encounted a compiling problem. In my user library, I have a class named Number. In J2SE 1.5, there is also a class named Number at java.lang.Number. So as I compiled the program,