Problem with getting word count in TLF text

Hi,
I want to get the word count from my TLF text, but the problem is that I am not being able to handle th case for space.
I am using the findNextWordBoundary property of ParagraphElement as shown below:
private function countWords( para : ParagraphElement ) : void
            var wordBoundary:int = 0;
            var prevBoundary:int = 0;
            while ( wordBoundary != para.findNextWordBoundary( wordBoundary ) )
               // If the value is greater than 1, then it's a word, otherwise it's a space.
                if ( para.findNextWordBoundary( wordBoundary ) - wordBoundary > 1)
                    wordCount += 1;                   
                prevBoundary = wordBoundary;
                wordBoundary = para.findNextWordBoundary( wordBoundary );                   
                // If the value is greater than 1, then it's a word, otherwise it's a space.
                if ( wordBoundary - prevBoundary > 1 )
                    var s:String = para.getText().substring( prevBoundary, wordBoundary );
                    lenTotal += s.length;
Now I have 2 issues here:
If my string is for eg: Hi, I am writing in "TLF". And I want to get its word count then
1) Suppose I take the case of the string Hi,  . Then para.getText().substring( prevBoundary, wordBoundary ) gives the text as Hi i.e without the comma. Same case for the string "TLF forums" , It treats each " as a single word and not the whole "TLF" as a single word. Why doesn't it compute till spaces, that should be the ideal case. So until we don't give a space it should count the whole thing as a word.
2) So now the problem is I have applied a condition   if ( wordBoundary - prevBoundary > 1 ) to check if it is a space i.e. if the diff is <= 1 it is a Space. But if I use this I miss out on single words. Like for eg if I have "Hi, This is a string" ,then 'a' is ignored too.
Now I could have added a check here along with the space check that the string between prevBoundary and wordBoundary is " "(i.e a space), Then also it is a problem as then the single words like a,&,I will be ignored.
So, now I am stuck with this issue and need some help from you guys.
Thanks

findNextWordBoundary is not going to serve your purpose.  I'd propose doing something like this:
// didn't test this but something like this - whitespace matches any set of 1 or more white space characters
static const whiteSpaceRegExp:RegExp = /[u0020|u000A|u000D]*/
public static function countWords( para : ParagraphElement ) : void
     return para.getText().split(whiteSpaceRegExp).length;
A good list of everything considered whitespace extracted from the unicode space can be found here:
http://sourceforge.net/adobe/tlf/svn/449/tree/trunk/textLayout/src/flashx/textLayout/utils /CharacterUtil.as
In function createWhiteSpaceObject
Hope that helps,
Richard

Similar Messages

  • Problem with Korean Word Counting

    After upgrading to Yosemite 10.10.3, Korean word counting in Pages got mesed up. Before the upgrade, there was no problem. But now Pages counts every single letter I typed as a "word." As a writer who should be sensitive to the number of words I type, this is very annoying. Is there anyone who experiences the same problem? is there any fix?

    See
    Korean word count

  • Just moved my email from entourage to Mail. Having real problems with getting my signatures to work properly. When adding in a small company logo, windows computers only receive signature as an attachment. Am sending email as Rich Text. Any ideas on a fix

    Just moved my email from Entourage to Mail. Having real problems with getting my signatures to work properly despite sending email as Rich Text.
    When adding in a small company logo to the signature, PC's / windows computers only receive signature and logo as attachments.
    I've tried all possible fixes I can find including getting a PC user to format the logo but no joy. Has anyone experienced this and any ideas on a fix gratefully received.

    Send it as html so the signature is an image source URL

  • TS2755 I am having a problem with getting notified when I receive a call or a text.  My phone will not ring or vibrate.

    I am having a problem with getting notified when I receive a call or a text.

    Hi BigBroMAC,
    The first thing I would check is Do Not Disturb mode, as this will cause that behavior:
    iOS 6: Using Do Not Disturb
    http://support.apple.com/kb/HT5463
    If that isn't the issue, this article has slightly different symptoms but the troubleshooting would be the same:
    iPhone: Can't hear through the receiver or speakers
    http://support.apple.com/kb/TS1630
    Before you do step 10, however, I recommend resetting all settings to see if that helps.  To do that, choose Settings > General > Reset > Reset All Settings.
    I hope this helps!
    - Ari

  • How do you get word count to print at the end of a document in Pages?

    How do you get word count to print at the end of a document in Pages?

    Pages v5 does not provide a user assignable word count variable. With some AppleScript, and a paste operation from the clipboard, you can have locale punctuated word count in this format: 7,803 — anywhere in your document. The following AppleScript works with Pages '09 v4.3 through Pages v5.5.2 on Yosemite.
    I would suggest that you copy paste the following AppleScript into your [Apple] Script Editor and save it (suggestion) wordcnt.applescript. Then, follow this with an option+Save As… and this time set the File format to Script Bundle, or Application with hidden extension — saved to your Desktop. Provided you have a Pages document open, you are then a double-click from the ability to paste your current word count into Pages.
    Note: If you have Pages word count display enabled, it will automatically count your pasted value as another word which initially may deceive on true word count at the time the script was run.
    AppleScript
    --- copy below this line ---
    property locale : "en_US.UTF-8" -- In Terminal, use the locale command to see yours
    if not ApplicationIsRunning("Pages") then
         display dialog "Pages must be running to use this utility."
         return quit
    end if
    tell application "Pages"
        tell body text of front document
            set wordCnt to count words
            -- Don't want punctuated numbers? Remove the single quote from printf format
            set the clipboard to (do shell script "export LC_ALL=" & locale & "; printf \"%'d\" " & wordCnt)
        end tell
    end tell
    on ApplicationIsRunning(appName)
         tell application "System Events" to set appNameIsRunning to exists (processes where name is appName)
         return appNameIsRunning
    end ApplicationIsRunning

  • Hi, I have a problem with getting my apple Id working for me. It's been 2 months since it happened and Apple failed to act. I can tell my story proerly, but am not sure, you guys can help, so I just copy my message to them today, I am trying to get it acr

    Hi, I have a problem with getting my apple Id working for me. It's been 2 months since it happened and Apple failed to act. I can tell my story proerly, but am not sure, you guys can help, so I just copy my message to them today, I am trying to get it across all the places around to pay their attention. This is a desperate move, so if you are not the right people to help me to get my message accross, may be you can advise where can I go.
    Thank you, and sorry for the language.
    Vitas Dijokas
    I am sorry to say that, but your security makes my life miserable – it’s been 2 months since my Apple ID account got stuck, and since then I cannot update 37 applications (to date), i.e. most of my applications. Half of them I bought. I also paid for iCloud, and it is not working. I paid money and I am stuck with old applications and no iCloud. Your security *****. Your service ***** too. It took your service 1 month to finally understand why this happened to me, and it took me tens of emails to you and 3 hours of telephone conversation to find out the reason for my problem. And the problem is still not fixed. NOT FIXED. You just leave your customer – the one who paid you money and spent so much time with you trying to help you help me – and nothing. You tell me:  “Vitas, Stick your stinky iphone in your *** and enjoy life, we do not care!” *************.
    It is ******* outrageous, and you should know that,  guys. Get into the ******* database and correct the bug. Get someone in the partners-telephone carriers company (it is Orange as carreer and Cellcom as seller of the phone)  authorized to Identify me in personal encounter in one of the branches in Israel (where I live) and make sure it is really me, and get the ******* system accept my password and let me use my phone.
    Otherwise **** off. None of my friends will get my advise to buy an iphone or any of apple products. And I think you should be very attentive to cases like this, guys. Do your work for the money we pay, or disappear. There are many others eager to take your place, and if the problem is not fixed I will eventually go to the others. My patience is lost, and as soon as I can afford another phone I will change it. AND I WILL TRY TO GIVE BAAAAAD PUBLICITY TO APPLE – I am threatening here, so ACT NOW.
    Vitas Dijokas

    Well, it seems waiting is not my strong suit..! I renamed a javascript file called recovery to sessionstore. This file was in the folder sessionstore-backups I had copied from mozilla 3 days ago, when my tabs were still in place. I replaced the sessionstore in mozilla's default folder with the renamed file and then started mozilla. And the tabs reappeared as they were 3 days ago!
    So there goes the tab problem. But again when I started mozilla the window saying "a script has stopped responding" appeared, this time the script being: chrome//browser/contenttabbrowser.xml2542
    If someone knows how to fix this and make firefox launch normally, please reply! Thank you

  • Problems with getting my Ipod Touch to work on my Sony Bravia or any TV

    I am having problems with getting videos or movies to play on my Sony Bravia HDTV or any TV. I have a first generation Ipod Touch and I have the Apple AV Composite Cables and all I get is sound for both TV's that I tried. I read one post where some guy had a faulty Ipod that wouldn't work. Does anyone know how of something hidden or special that needs to be done or how did they fix the problem if they had the same one? Thank, ejcarlson

    Check connection, if you have a case on your Ipod the connection may not be good enough.

  • Problem with getting resized image's bytes

    I've got a problem with getting correct bytes of a newly resized image. The flow is that I retrive an image from the filesystem. Due to the fact that it is large I resize it to a 50x50px thumbnail. I can display this thumbnail in #benchmark1 (see code below). Unfortunately something's wrong with my imageToBytes funtion which returns reasonably small size of image but is totally useless - I can't make an image of it anymore so at #benchmark2 the application either crashes or keeps freezing. I saved this byte array on my disk and tried to preview under Windows how does it look but I got a message "Preview unavailabe". I did some digging in the Internet and I supposed that it's because I don't use any jpg or png encoders to save the file. Actually I think that it's not the case, as the bytes returned from method imageToBytes look weird - I cannot even make a new image of them and display it without any saving in memory.
                                  byte[] bytes = FileHandler.readFile (
                                          FileHandler.PHOTOS_PATH, fileName);
                                  Image img2 = Image.createImage (bytes, 0, bytes.length);
                                  img2 = ImageHandler.getInstance ().resize (img2);
                                                    //#benchmark1
                                  bytes = ImageUtils.imageToBytes (img2);
                                  img2 = Image.createImage (bytes, 0, bytes.length);
                                                    //#benchmark2my imageToBytes function is as follows:
         public static byte[] imageToBytes (Image img)
              int[] imgRgbData = new int[img.getWidth () * img.getHeight ()];
              byte[] imageData = null;
              try
                   img.getRGB (imgRgbData, 0, img.getWidth (), 0, 0, img.getWidth (),
                           img.getHeight ());
              catch (Exception e)
              ByteArrayOutputStream baos = new ByteArrayOutputStream ();
              DataOutputStream dos = new DataOutputStream (baos);
              try
                   for (int i = 0; i < imgRgbData.length; i++)
                        dos.writeInt (imgRgbData);
                   imageData = baos.toByteArray ();
                   baos.close ();
                   dos.close ();
              catch (Exception e)
              return imageData;
    I've run totally out of any idea what's wrong, please help!
    Edited by: crawlie on Jul 17, 2010 6:21 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    Hey Crawlie,
    Please note that simply writing int values into ByteArrayOutputStream will not suffice. Please have a look at the following conversion from int pixel value into byte[4]:
    public static final byte[] intToByteArray(int value) {
            return new byte[] {
                    (byte)(value >>> 24),
                    (byte)(value >>> 16),
                    (byte)(value >>> 8),
                    (byte)value
    }Good Luck!
    Daniel

  • Problem with getting iPod to work.

    I'm having a problem with getting an iPod to connect to my computers. Also I can't even really get it to run. My brother gave it to me one or two years ago and it had these problems I just didn't think of the idea of going directly to Apple to figure it out. It's a 30 GB black iPod if that helps. When I plugged it in it showed the battery symbol. When I leave it for a while it shows the Apple symbol. Then it comes up with this: http://spirrwell.webatu.com/ipod.jpg If you can help thanks in advance!
    Message was edited by: Spirrwell

    I figured out that it was a hard drive problem so I'll find a fix if not I guess I'm screwed.

  • Problem with non iPhone users receiving my text sent pictures. Can I make them smaller files?

    Problem with non iPhone users receiving my text sent pictures.  Can I make them smaller files? I know that is possible for email sent pics.

    My bad,  It was a Verizon problem.  When they upgraded my phone they were supposed to remove all blocks on messaging . Found out they did not do this.  All messaging now works.  Thanks for listening.

  • Problem with getting the little blackberry icon

    Hi the blackberry I'm using is working and up to date. I was setting up my mates blackberry 9320 but having a problem with getting the little blackberry icon to appear in the top right corner of my phone where the GMS is and signal bar and stuff its something to do with blackberry.
    I tried downloading bbm and it say associating bbm with blackberry id and constant loads with nothing happening bbm not working
    I NEED THE TINY BB ICON AT TOP RIGHT???

    Hi neal123
                            That BlackBerry icon will appear near signal bar when we activate  BIS on a 3G device. Did he activated BIS on his account. ? 
    Click " Like " if you want to Thank someone.
    If Problem Resolves mark the post(s) as " Solution ", so that other can make use of it.

  • Problems with saving Word 2007 table as PDF

    I have a table in MS Word 2007 with some merged cells. If I use the Save as ... PDF or XPS option in Word 2007 to save this document as a PDF, the resulting PDF has a table with a discontinuous table grid. The table lines around the cells are broken.
    Is this a problem with the Word table or does the Save as PDF command not work well with tables.
    Thanks,
    Karl Smith

    What versions of both programs and how did you create the PDF? Can you post an example of the PDF?

  • I still have problems with getting my website online. I have defined my server. Then I did the test and there was a connection via FTP. I put my files on the external server and there is a connection with the external server. But when I check to see my we

    I still have problems with getting my website online. I have defined my server. Then I did the test and there was a connection via FTP. I put my files on the external server and there is a connection with the external server. But when I check to see my website online (with Firefox, Explorer, Chrome browser) I always get the message 'Forbidden, You don't have permission to access / on this server.' Can somebody help me please? I have to get my website online..Thank you!

    Hello Els,
    it's well known, that in all these cases you describe I'm not a friend of a detailed Troubleshooting (I see Nancy#s smile already).
    To be able to be independent in all this things It is one of the reasons why I prefer an external FTP program. The difficulties with which you have to fight encourage me in this opinion, not least because we always search for experts, we don't charge a "jack of all trades".
    To manage several websites or to upload my files and sometimes for the opposite way, for a necessary download from my server or to use a "a site-wide synch", I'm using FileZilla. It simply looks easier for me to keep track of all operations precisely and generate or reflect easily the desired tree structure.
    Above all, FileZilla has a feature (translation from my German FileZilla) called "compare file list". Here it's possible to use file size or modification time as a criterion. There is also the possibility to "hide identical files", so that only these files which you want to redact remain visible.
    And even if it means you have to install a new program, I am convinced that there is an advantage. Here is the link to get it and where you can read informations about how it works:
    http://filezilla-project.org/ and http://wiki.filezilla-project.org/Tutorial#Using_the_site_manager
    Mac: Mac OS X (Use: Show additional download options)
    http://filezilla-project.org/download.php
    Of course, you also need all the access data to reach your server and for MIME issues, you should contact your web host/provider.
    Good luck!
    Hans-Günter
    P.S.
    Since I use two screens, the whole thing became even more comfortable.

  • Problems with Microsoft Word 2011

    Hello,
    So, I'm having a slight problem with Microsoft Word 2011. Yes, I realize this isn't exactly Apple related, but I was wondering if it had to do with a compatibility issue with Lion.
    I'm running version 10.7.3, and I've found that when I try and change my language in Microsoft Word to English (Canada) - also have tried English (Britain) - and neither of them have changed successfully. My system language is also Canadian English, but none of these options seem to stop my Microsoft Word from trying to correct Canadian English spelling.
    If anyone knows if there has been updates to Microsoft Word for this issue, please let me know. I thought it would be worth a shot asking here, as I could find nothing anywhere else.

    You may also want to search/ask in the forums run by the make of this app to deal with its problems:
    http://answers.microsoft.com/en-us/mac/forum/macword

  • I am having problems with my droid incredible 2 loading texts and so I thought maybe I had too many saved, I tried to delete some of them and it wont seem to delete either?

    I am having problems with my droid incredible 2 loading texts and so I thought maybe I had too many saved, I tried to delete some of them and it wont seem to delete either?

    Did you pull the battery?

Maybe you are looking for

  • Using text-to-speech technology in my web app

    Hi all, I work for a small web development company and we're curently in the process of building a web app for foreign language learners. One of the features we'd like to have is speech synthesis. We immediately thought about incorporating the techno

  • F5670: No Account Assignment for line item 002 account type S

    Hi Experts I have created assesment cycle for transfering cost from an cost center to an statistical order. While executing assesment cycle in test run, it executes successfully. But when I take out the test run tick, it gives above error. Pls help R

  • Trying to use AVTransmit with AVReceive

    I am working on a video conferencing app that leverages multicast. I am new to JMF so please forgive my newbie status. I would like to receive Audio/Video streams on my app and retransmit them via multicast. My main question is can I receive a RTP/Vi

  • Installing the Oracle ODBC driver

    Is there any way to wrap only the oracle odbc driver in an install program? we want to avoid having to go through an entire oracle client install. Any help would be much apprecitaed. null

  • Some DCs are not available locally - NWDS error while importing Track confg

    Hi, We have configured NWDI in our landscape. As per the requirement of the developers, we have created a new product and software component (SC) in SLD, as they don't want to use any standard components. The same has been synced with CMS using updat