Word count program..twisting my mind

Hi fellow Java lovers , i'm new on this forum and I had a little tricky java program. Apparently I have a piece of text , about 1500 words long (in french) and I need to come with a code that makes it possible:
1.Load up the piece of text using a menu option , convert it to lower case and display it.
2.Display average word length
3.Display number of commas per 1000 words
4.Display number of times the word "le" occurs per 1000 words. (tip: u will hav to search for space followed by "l" then "e"...> " le " otherwise java will pick it as part of a word)
5.Allow a search to b done for any word and display number of times it occurs.
Anyone wanna come to my rescue ?

Try this:
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
public class CandyGirl1
     static class DisplayPanel
          extends JPanel
          private JTextArea mTextArea= new JTextArea();
          private JLabel mLabel= new JLabel(" ");
          public DisplayPanel()
               mTextArea.setEditable(false);
               setLayout(new BorderLayout(4,4));
               add(new JScrollPane(mTextArea), BorderLayout.CENTER);
               add(mLabel, BorderLayout.SOUTH);
          public Dimension getPreferredSize() {
               return new Dimension(600, 480);
          public void setText(String text)
               text= text.toLowerCase();
               mTextArea.setText(text);
               mLabel.setText(
                    "<html>" +
                    "Average word length: " +getAverage(text) +"<p>" +
                    "Commas per 1,000 words: " +getCommas(text) +"<p>" +
                    "Occurences of 'le': " +getOccurs(text, "le") +"<p>" +
                    "</html>");
          public void search(String what)
               mLabel.setText(
                    "Occurences of '" +what +"' : " +getOccurs(mTextArea.getText(), what));
          private int getOccurs(String text, String what)
               int count= 0;
               StringTokenizer st= new StringTokenizer(text, " ");
               while (st.hasMoreTokens()) {
                    if (st.nextToken().equals(what))
                         count++;
               return count;
          private int getCommas(String text)
               int i= 0;
               int cnt= 0;
               for (; i< text.length(); i++) {
                    if (text.charAt(i) == ',')
                         cnt++;
               return (1000/text.length())*cnt;
          private int getAverage(String text)
               int count= 0;
               int length= 0;
               StringTokenizer st= new StringTokenizer(text, " ");
               while (st.hasMoreTokens()) {
                    length += st.nextToken().length();
                    count++;
               return length/count;
     static class Application
          extends JFrame
          private DisplayPanel mDisplayPanel= new DisplayPanel();
          public Application()
               getContentPane().add(mDisplayPanel);
               JMenuBar bar= new JMenuBar();
               setJMenuBar(bar);
               JMenu menu= new JMenu("File");
               menu.setMnemonic(KeyEvent.VK_F);
               bar.add(menu);
               JMenuItem item= new JMenuItem("Open");
               item.setMnemonic(KeyEvent.VK_O);
               menu.add(item);
               item.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) { open(); } });
               item= new JMenuItem("Search");
               item.setMnemonic(KeyEvent.VK_S);
               menu.add(item);
               item.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) { search(); } });
          private void search()
               String what= JOptionPane.showInputDialog(this, "Serach for:");
               if (what != null)
                    mDisplayPanel.search(what);
          private void open()
               JFileChooser chooser= new JFileChooser();
               if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION)
                    open(chooser.getSelectedFile());
          private void open(File file)
               try  {
                    FileReader reader= new FileReader(file);
                    StringBuffer str= new StringBuffer();
                    char[] buf= new char[128];
                    while (true) {
                         int read= reader.read(buf, 0, buf.length);
                         str.append(buf, 0, read);
                         if (read < buf.length)
                              break;
                    mDisplayPanel.setText(str.toString());
               catch (Exception e) {
     public static void main(String[] argv)
          Application frame= new Application();
          frame.pack();
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setVisible(true);
}

Similar Messages

  • Adapting My Word Counter Program to also Search and Replace

    Hi,
    I recently completed a word counter program for a school assignment. It reads in a file name from the command line and prints the contents to the screen before counting the number of words. i now want to try and adapt this program to also search for and replace a word specified by the user and print the document back to the creen with the changes. it would work something like this:
    java SearchReplaceApp test.txt
    This is a test
    This is a test
    This is a Test
    This is a Test
    This file contains 16 words
    Search for?: test
    Replace with?: Test
    This is a Test
    This is a Test
    This is a Test
    This is a Test
    Search for?:
    etc..........
    I was planning on using the replaceAll method and obviously i would neeed some kind of loop structure (probably a do/while loop) but i dont really know how to implement this in this scenario.
    Any suggestions would be appreciated. NEWBIE ALERT!!!!!! im afraid as i have very little programming experience, so please keep it as simple as possible please.
    maybe i'll give you a hug or something

    Just to make it easier for you guys to understand heres the code i have for my word counter, which i have now renamed SearchReplaceApp:
    import java.io.*;
    import java.util.*;
    class SearchReplaceApp
                public static InputStreamReader input =
                                       new InputStreamReader(System.in);
                public static BufferedReader keyboardInput =
                                       new BufferedReader(input);
                public static void main(String[] args) throws IOException
                                      FileReader file = new FileReader(args[0]);
                                      BufferedReader MyFile = new BufferedReader(file);
                                      StringTokenizer TokenizeMe;
                                                int NumberOfTokens = 0;
                                                int NumberOfWords = 0;
               TokenizeMe = new StringTokenizer(MyFile.readLine());
               NumberOfTokens = TokenizeMe.countTokens();
               while (NumberOfTokens != 0)
                                        for (int WordsInLine=1; WordsInLine<=NumberOfTokens;
                                                                        WordsInLine++)
                                                     System.out.print(TokenizeMe.nextToken()+" ");
                                        System.out.println();
                                        NumberOfWords += NumberOfTokens;
                                        String line = MyFile.readLine();
                                        if (line==null) break;
                                       TokenizeMe = new StringTokenizer(line);
                                       NumberOfTokens = TokenizeMe.countTokens();
                 System.out.println("\nThis file contains " + NumberOfWords + " words");
                 MyFile.close();
    }as you can see it does use a tokenizer, i would ideally like to be able to replace parts of words as well as whole words and also prompt for another search word after displaying the updated file e.g.
    This is a test
    Search for?: is
    Replace with?: was
    Thwas was a test
    Search for?:
    im really quite stuck on this so suggestions of any kind are welcome
    thanks

  • Help with a Word Counting Program..

    I need some help with a program I am trying to write
    The program is being written in BlueJ.
    Im just starting the program and am completely confused on how I should write this...
    But here is what I have to do..
    I have to use a scanner to scan a Text file and count the # of Words the number of Vowels (including Y when it is) and the # of Palindromes (Word spelled same forward and Back) as well as which Palindromes are being used.
    It would be good to have a class to clean the text and a seperate class for the tasks...
    I do not want to use anything other than "If" statements and while loops (no "for" loops) and only use Printwriter as the output file writer.
    Thnx to anyone in advance

    I have a basic Vowel coding that doeswnt work...
    public class vowel{
    String word = "heyyou";
    String vowels = "aeiouy";
    int[] countv = new int[vowels.length()];
    int countv2;
    int i=0;
    if(i<word.length();) { i++ {
    if (int j=0 && j<vowels.length()) {
    return j++;
    if (word.charAt(i)==vowels.charAt(j)) {
    countV[j]++; countV2++;
    for (int i=0; i<vowels.length(); i++) {
    System.out.println("Vowel "vowels.charAt(i)" = "+vcnt);
    System.out.println("Consonants = "+(word.length()-vtot)); }
    I also have a basic Palindrome code that works as a boolean but I need to make it return what the palindromes are and how many of them are there. I wanna know how I would do this.
    public class Palindrome{
    public static boolean isPalindrome(String word) {
    int left = 0;
    int right = word.length() -1;
    while (left < right) {       
    if (word.charAt(left) != word.charAt(right)) {
    return false;
    left++;
    right--;
    return true;
    I would also like to know how to actually start writing the word counter.

  • I'm writing a word-count program

    I'm sure this question has come up often but I've searched the web and haven't found a straight-forward answer for my problem. I need to write out a program that simply counts the number of words in a file of text.
    This has to be done in two different ways:
    1)Using a string object where I input each line.
    2)Assuming the string class doesn't exist, and to input the data one character at a time.
    Now, I know you won't do the work for me, and I haven't been able to figure out any code to put in yet. I just could use a push in the right direction with this. I haven't been able to find any good examples of this type of programming.

    1)Using a string object where I input each line.You could [url http://javaalmanac.com/egs/java.io/ReadLinesFromFile.html]read the text file line by line.
    For each line you could [url http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html#split(java.lang.String)]split it using [url http://java.sun.com/j2se/1.5.0/docs/api/java/util/regex/Pattern.html#sum]the regular expression character for whitespace (zero or more times).
    The number elements of the returned array is is the word count for each line.
    2)Assuming the string class doesn't exist, and to input the data one character at a time.You could still read the text file in the same way as previously but instead of using the readLine() method
    you should use the [url http://java.sun.com/j2se/1.5.0/docs/api/java/io/BufferedReader.html#read()]read() method.
    Each time the returned byte is either ' ', '\t', '\f', '\r' or '\n' (and that the previous byte is not) you could increment the word counter.
    Regards

  • Word counting program - new to strings

    Im trying to write a program that will tell me how many times the word "rabbit" appears in a text file. This is what I ahve so far and I am not sure if it is correct. I get a cannot find symbol
    symbol : method indexOf(java.lang.String) error when I compile.
    import java.util.Scanner;       
    import java.io.File;            
    import java.lang.String;
    public class Rabbitcount
      public static void main( String[] args ) throws Exception  // new: throws Exception, copy and paste for now
        File f = new File("rabbit.txt");
        Scanner input = new Scanner(f);
      while (true) {
      int x = indexOf("rabbit");
        System.out.println("There are " + x + " occurences of rabbit in the text.");
    // Close the file
        input.close();  
    } Any help is appreciated
    Edited by: euchresucks on Nov 3, 2008 2:23 PM

    indexOf() is a String method. If you were going to use that, you would have to load the file's contents into a String and call indexOf() on that String. You would also need to use the two-argument form of indexOf() so you could start each search at the point where the last match ended.
    But you don't need to do any of that. You've already a perfectly good Scanner there; use it to do the searching. Hint: the name of method you need does not start with the word "next".

  • Word Count Discrepancy

    I am editing a document in Pages for iOS (iPad) but am getting a discrepancy in word count when compared to the same document in Word 2010. Both documents are unaltered from when I opened them (from an email), but Pages tells me it's 1,130 whereas Word is giving me 1,045. Any ideas why?

    Interesting Quesion:)
    In theory, the Character Count in Windows Explorer gets the same result as the Characters(no spaces) value in Word Count.
    However, the operational definitions of how to count the words can occur (namely, what "counts as" a word, and which words "don't count" toward the total) is similar but different. Different word counting programs may give varying results, depending
    on the text segmentation rule details, and on whether words outside the main text (such as footnotes, endnotes, or hidden text) are counted.
    In your story, the Character count in Windows Explorer(28877) is lower than the result in Word count (27286). It's difficult for me to figure out the root exactly duo to:
    the space (any of various whitespace characters, such as a "regular" word space, an em space, or a tab character)
    hyphen or a slash
    Asian/Non-Asian words.
    All of them above might be the factors in this case. Hope the info light you.
    Cheers,
    Tony Chen
    Forum Support
    Come back and mark the replies as answers if they help and unmark them if they provide no help.
    If you have any feedback on our support, please contact
    [email protected]

  • Word count and my ActionPerformed

    I am having a little trouble with my program and was wondering if anyone could spot the mistake... I am trying to make a simple application that will count the number of words in a text field via click of a button and display the results.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.text.*;
    public class WordCount extends JFrame implements ActionListener
    // added JTextPane, JScrollPane, JPanel JTextField, and JButton
        public static void main(String[] args)
         // layout
        public WordCount()
              super();
              Container cp = getContentPane();
              wordCount.setEditable(false);
              south.setLayout(new FlowLayout(FlowLayout.CENTER));
              south.add(jbtCount);
                   jbtCount.addActionListener (this);
              south.add(new JLabel("  Word Count: "));
              south.add(wordCount);
              cp.add(BorderLayout.CENTER,jsPane);
              cp.add(BorderLayout.SOUTH,south);
         public void actionPerformed(ActionEvent e)
              //if(e.getSource() == jbtCount)   // user clicks Count Words Button
              Object s = e.getSource();
             if ( s instanceof Button )
                  jtPane.setDocument(new DefaultStyledDocument() {
                        public void insertString(int offset, String str, AttributeSet as) throws BadLocationException
                           super.insertString(offset,str,as);
                           String text = jtPane.getText();
                           String[] tokens = text.split(" ");
                           wordCount.setText("" + countValid(tokens));
                         public void remove(int offset, int len) throws BadLocationException
                           super.remove(offset,len);
                           String text = jtPane.getText();
                           String[] tokens = text.split(" ");
                             wordCount.setText("" + countValid(tokens));
                  else{}
         } // end actionPerformed
         private int countValid(String[] tokens)
              int count = 0;
             for (int i = 0; i < tokens.length; i++)
                    if (tokens.trim().length() != 0)
              count++;
         return count;
    } // end public class WordCount

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.text.*;
    public class WordCount extends JFrame implements ActionListener
         JTextPane jtPane = new JTextPane();
         JScrollPane jsPane = new JScrollPane(jtPane);
         JPanel south = new JPanel();
         JTextField wordCount = new JTextField(20);
         JButton jbtCount = new JButton("Count Words");
        public static void main(String[] args)
              int width = 700;
              int height = 300;
               WordCount f = new WordCount();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
             f.setSize(width, height);
             f.setTitle("Word Counter");
             f.setLocation(200, 200);
             f.setVisible(true);
        public WordCount()
              super();
              Container cp = getContentPane();
              wordCount.setEditable(false);
              south.setLayout(new FlowLayout(FlowLayout.CENTER));
              south.add(jbtCount);
                   jbtCount.addActionListener (this);
              south.add(new JLabel("  Word Count: "));
              south.add(wordCount);
              cp.add(BorderLayout.CENTER,jsPane);
              cp.add(BorderLayout.SOUTH,south);
         public void actionPerformed(ActionEvent e)
              //if(e.getSource() == jbtCount)   // user clicks Count Words Button
              Object s = e.getSource();
                  // *** process Button actions
            if ( s instanceof Button )
                  jtPane.setDocument(new DefaultStyledDocument() {
                        public void insertString(int offset, String str, AttributeSet as) throws BadLocationException
                           super.insertString(offset,str,as);
                           String text = jtPane.getText();
                           String[] tokens = text.split(" ");
                           wordCount.setText("" + countValid(tokens));
                         public void remove(int offset, int len) throws BadLocationException
                           super.remove(offset,len);
                           String text = jtPane.getText();
                           String[] tokens = text.split(" ");
                             wordCount.setText("" + countValid(tokens));
                  else{}
         }// end actionPerformed
         private int countValid(String[] tokens)
              int count = 0;
             for (int i = 0; i < tokens.length; i++)
                    if (tokens.trim().length() != 0)
              count++;
         return count;
    } // end public class WordCount

  • Why is the word count function inaccurate in tables?

    Why, when using tables in pages the word count function gives a total that is double the amount of words in the table? This has been a problem with Pages for sometime now. Additionally, is there a quick way of highlighting all the words in the table to give a word count total, similar to highlighting a paragraph, sentence or just a few words?

    Pages v5.2.2 (and probably 5.5) will total all the words in the body of a document (including those in a table) accurately in my experience. Since the Pages v5 family does not permit non-contiguous text selection, your only other way to count just words within the table is from the Statistics component of the free WordService Services package. Just select the table, and then from the Services menu, choose Statistics. The word count matches the table contents.
    Unfortunately, the AppleScript dictionary  for the Pages v5 family excludes any means to address words or characters within cells. The fact that Pages is counting words in the table, is due to native programming, and not AppleScript.

  • Trying to write Javascript code to get word count

    I copied code from an internet source and spent hours making adaptations so that my code would compile in Adobe Acrobat XI form Actions.
    Nothing I can do will make the script recognize that a character is a space. I need to count spaces so that I can count words.
    Finally I gave up and tried to use Replace to replace spaces with some other character that perhaps the program would recognize, but I can't get the Replace method to work either. Well, I can get it to work for the first instance of a space in the string, but not replace all spaces in the string. I have tried the "/text/g" convention and the "text,newtext,"All" convention. Do I really have to write another loop to replace the spaces individually?
    It seems so odd that there aren't more simple functions in Java (I'm new to Java) - it's like programming in machine language. And every function I investigate has more than one syntax I guess depending on what version Javascript you are using - and I can't even find out which version of Javascript Acrobat Pro XI is using!
    Following is my code - I will be doing something with the wordCount - this is just an initial snippet:
        var f = getField(event.target.name);
        var input = f.value;
        var wordCount = 0;
        if (input.trim.isEmpty){
            wordCount = 0;
        else {
            wordCount = 1;
        for (var i = 0; i < input.length; i++) {
            var ch = input.charAt(i);
            var str = new String("" + ch);
    //        if (i+1 != input.length) && (str == " ") && (!("" + input.charAt(i+1)) = " ")){
            if (i+1 != input.length && str === " " && "" + input.charAt(i+1) !== " "){
                wordCount++;
    app.alert (wordCount);

    See adracadabraPDF.net and the free utilities they offer. There is a word counter by page and document.
    The example from the Acrobat JS API Reference:
    Example
    Count the number of words in a document
    var cnt=0;
    for (var p = 0; p < this.numPages; p++)
    cnt += getPageNumWords(p);
    console.println("There are " + cnt + " words in this doc.");
    The above is for the content in a PDF.
    If you want to count the words in a form field, you need to determine how you want to split the field value and change certain white space characters to a given character like a space.
    You can use the "split()" method to convert  a field value to an array of items based on the "split" character.
    If your entry is just a line of text and does not have have any punctuation for string termination you can use
    var aWords = event.value.split(" ");
    console.println("Number of words: " + aWords.length;

  • Words count on keynotes

    How to do words count on key notes program?

    Hi,
    this will do it for you:
    SQL> select *
      2  from order_header;
            ID ORG          CUSTOMER
             1 A                   1
             2 A                   1
             3 A                   1
             4 B                   1
             5 B                   1
             6 B                   1
    6 rows selected.
    SQL> select *
      2  from order_lines;
    ORDER_HEADER_FK       ITEM        QTY
                  1          1          1
                  1          2          1
                  1          3          1
                  2          1          1
                  2          2          1
                  4          1          1
    6 rows selected.
    SQL> select org,
      2         count(distinct id) org_headers,
      3         count(distinct order_header_fk) with_lines,
      4         count(distinct id)-count(distinct order_header_fk) without_lines
      5  from order_header,
      6       order_lines
      7  where id = order_header_fk (+)
      8  group by org
      9  ;
    ORG        ORG_HEADERS WITH_LINES WITHOUT_LINES
    A                    3          2             1
    B                    3          1             2
    SQL>Regards,
    Gerd

  • Word Count?? Anywhere? Please?!

    I just recently switched from Windows to Mac. I love this new word processing program, but I can't seem to find one key tool that Microsoft Word has - the word counter!! Does Pages have a word counter?? Please help, I need this for school! Thanks everyone:)
    Also, does anyone know how to change your alias on this discussions board? The name I chose was a bit impulsive, and I'd like to go with a different one if possible! Thanks again~
    <3D

    Welcome to Apple Discussions, Weezy's Deezy!
    Does Pages have a word counter??
    Yes, see this thread:
    http://discussions.apple.com/click.jspa?searchID=7127794&messageID=6520088
    Also, does anyone know how to change your alias on this discussions board?
    It is not possible. Apple has chosen to lock you in to a single alias. If you want to use a different one, stop using this account and set up a new one. Sorry.

  • Word Count Method?

    Hey all. I am having a bit of an issue. I need to write a program to read a file and count how many words are in the file. So far I have the basis for the while loop to read a line from the file, but I can't seem to figure out how to code the loop to count the words. Java doesn't have a word count method does it? I have looked, but have been unable to find anything of the sort.
    I don't want you do do this for me, I just need some helpful hint/tips. Anything you can provide is appreciated. Thanks!

    I am now having this problem. Here is a code segment:
    void count(String newFileName) throws IOException
              fileName = newFileName;
              FileRead file = new FileRead(fileName);
              wordCount = 0;
              StringTokenizer st = new StringTokenizer(fileName);
              while (file.getLine() != null)
                 while ( st.hasMoreTokens() )
                    st.nextToken();
                    wordCount++;
         }I think it should be changed to StringTokenizer st = new StringTokenizer(file) but when I do so, I get the error "The constructor StringTokenizer(FileRead) is undefined". I assume this is because file is an object not a String variable. the current code has a problem because it only returns 1. Any ideas?
    Edited by: zcrane on Nov 1, 2007 3:40 PM

  • TextEdit Word Count?

    Hi folks, I'm relatively new to Apple. (New enough to not know the proper forum for this question, though). Can I do a word count in TextEdit? If so, how? Any help is greatly appreciated.

    Here is the applescript to tell you the word count:
    tell application "TextEdit"
    set WordCount to the number of words in the the front document
    display dialog "The wordcount is: " & WordCount
    end tell
    What you need to do to install this is this:
    Run the program called "Scripteditor", which you can find somewhere in the programs directory - there is no point in my trying to tell you where as my system is set up in Foreignspeak. You'll have to run a search, which thankfully is very easy!
    To make a new script press apple-n, then copy and paste the text I gave above into the window that appears. Then run the script and it will tell you how many words there are in your current TextEdit file.
    There is probably a neater way of running the script than opening ScriptEditor, but given that I have been playing with this stuff for only a very short period of time I don't know about it yet.
    Best Wishes, Max
    p.s. My favourite script of the moment, which speaks whatever I type:
    set toSay to "I would like a cup of tea."
    repeat
    set toSay to the text returned of (display dialog "Max doeth speak:" default answer toSay)
    say toSay
    end repeat
    (childish, I know!)
      Mac OS X (10.4.3)  

  • Word Count, but only words over certain number of letter...?

    Hi,
    Does anyone know of a way to do a word count, but only count the words with a certain number of letters. For example all words with 4 letters or more?
    Thanks

    I never guessed that I will read such a question but why not ?
    --(SCRIPT word4Count.app]
    --==========
    Enregistrer le script en tant qu'Application ou Progiciel : word4count.app
    déplacer l'application créée dans le dossier
    <VolumeDeDémarrage>:Users:<votreCompte>:Library:Scripts:Applications:Pages:
    Il vous faudra peut-être créer le dossier Pages et même le dossier Applications.
    menu Scripts > Pages > word4count
    Le script affiche (ou insère à l'emplacement du curseur )
    le nombre de mots de la couche texte et
    le nombre de mots des blocs texte
    dont la longueur est supérieure à la valeur définie par la property limite.
    --=====
    L'aide du Finder explique:
    L'Utilitaire AppleScript permet d'activer le Menu des scripts :
    Ouvrez l'Utilitaire AppleScript situé dans le dossier Applications/AppleScript.
    Cochez la case "Afficher le menu des scripts dans la barre de menus".
    --=====
    Grace au programme gratuit ThisService, il est possible d'encapsuler ce script dans un service.
    Télécharger ThisService depuis:
    http://wafflesoftware.net/thisservice/
    Lors de la création du service, cliquer le bouton "Produce output".
    Il est possible d'associer un raccourci clavier au service.
    --==========
    Copy the script in the clipboard
    Paste in a blank window of Script Editor
    Save it as an Application or an Application Bundle
    Move the newly created application into the folder:
    <startup Volume>:Users:<yourAccount>:Library:Scripts:Applications:Pages:
    Now, enter your Pages document.
    Click where you want.
    Go to
    menu Scripts > Pages > word4count
    The script will count the words whose length is higher than the value stored in the property limite.
    The wordcount will be pasted at the insertion point
    --=====
    The Finder's Help explains:
    To make the Script menu appear:
    Open the AppleScript utility located in Applications/AppleScript.
    Select the "Show Script Menu in menu bar" checkbox.
    --=====
    Thanks to the free program ThisService, we may encapsulate this script in a Service.
    Download ThisService from
    http://wafflesoftware.net/thisservice/
    When creating the service click the button "Produce output"
    We may link the service to a shortcut.
    --==========
    Yvan KOENIG
    19 février 2009
    --=====
    property limite : 4
    property affiche : true
    --=====
    property theApp : "Pages"
    property ws : {}
    --=====
    on process()
    set rezult to my commun()
    tell application "System Events"
    activate
    display dialog rezult
    end tell
    return ""
    end process
    --=====
    on commun()
    local liste1, liste2, ng, c1, c2
    --set my ws to {}
    tell application "Pages" to tell document 1
    set liste1 to words of body text
    set liste2 to {}
    set ng to count of graphic
    repeat with i from 1 to ng
    tell graphic i
    try
    copy items of (get words of object text) to end of liste2
    end try
    end tell -- graphic i
    end repeat
    (* Working this way we are counting the words as they are defined by Pages *)
    end tell -- document 1 of Pages
    if liste1 is not {} then
    set my ws to liste1
    set c1 to my compte4()
    else
    set c1 to 0
    end if
    if liste2 is not {} then
    set my ws to liste2
    set c2 to my compte4()
    else
    set c2 to 0
    end if
    set my ws to {}
    if my parlefrancais() then
    return "Nombre de mots dont la longueur dépasse " & limite & return & "dans la couche texte : " & c1 & return & "dans des blocs : " & c2
    else
    return "Count of words whose length is greater than " & limite & return & "in text layer : " & c1 & return & "in text blocks : " & c2
    end if
    end commun
    --=====
    on compte4()
    local wc, w
    set wc to 0
    repeat with w in my ws
    if length of (w as text) > limite then set wc to wc + 1
    end repeat
    return wc
    end compte4
    --=====
    on parlefrancais()
    local z
    try
    tell application theApp to set z to localized string "Cancel"
    on error
    set z to "Cancel"
    end try
    return (z = "Annuler")
    end parlefrancais
    --=====
    on run
    set rezult to my commun()
    if affiche then (*
    display the results *)
    tell application theApp to display dialog rezult
    else (*
    insert the results in the text body *)
    tell application "Pages" to tell document 1 to set selection to rezult
    end if
    end run
    --=====
    --[/SCRIPT]
    Yvan KOENIG (from FRANCE jeudi 19 février 2009 15:45:56)

  • Adobe bridge cc is not working on my mac snow leopard version 10.6.8. In other words the program will not open all other programs work fine

    Adobe bridge cc is not working on my mac snow leopard version 10.6.8. In other words the program will not open, but all other programs i have been able to open just fine

    Moving this discussion to the Bridge General Discussion forum.

Maybe you are looking for

  • Can i install gtx titan on mac pro*

    can i install gtx titan on mac pro* help please Thanks

  • How can I get the CODEC DVCPRO HD 100 for Premiere CS5?

    how can I get the CODEC DVCPRO HD 100 for Premiere CS5?

  • Trying to load iTunes onto Windows XP

    Sorry I posted this on the wrong forum before.... J :o) Hello! I bought my iPod on Friday. My pc runs on Windows XP and I have Norton as a virus scanner. Installed the iTunes/Quicktime from the cd-rom no problem. When I opened iTunes it told me there

  • Usb flash and truecrypt [Solved]

    I'm running kernel 2.6.19. Yesterday installed truecrypt and encrypted my usb flash. ]$ truecrypt --properties /dev/sda1 Enter keyfile path [none]: Enter password for '/dev/sda1': Volume properties: Location: /dev/sda1 Size: 1001111040 bytes Type: No

  • DirSync without exchange 2003

    Hello, I am currently operating in the cloud fully, without any hybrid setup.  But I have an old exchange 2003 server, from which I migrated to office365 still in the AD domain.  I plan on fully removing it and any exchange organization information.