Removing whitespaces and weird characters

Hi,
I need a way to remove the whitespaces and punctuation marks from a String.
So for example,
"This is a cool racecar!, right?"
should be read as
"thisisacoolracecarright"
After googling for a while, I think I can use a split() method or a BufferedReader, but I don't know how to proceed. Can anyone point me in the right direction?
This is part of my homework, so I really don't want you to solve it for me, but just help me look in the API or type in a sample code.
Help would be greatly appreciated.
-Rommel.
PS: 10 duke starts to be awarded.
Edited by: RommelTJ on Sep 15, 2008 9:52 PM

Sorry for the super late reply, but I couldn't forget to come back and award the Duke Stars.
Ravi_Gupta wrote:
while (!inputWord.isEmpty())Always true because you are not modifying the inputWork.
Try something like this:
for(int i=0;i<inputWord.length(); i++)
ch = inputWord.charAt(i);
if (ch>='A' && ch<='Z' || ch>='a' && ch<='z'){
} //end if statement.
} //end while statement.
This is what I ended up doing:               System.out.println("Please type a word, sentence, or phrase to be checked:");
              inputWord = StdIn.readLine();                               //records the word inputted(?) by the user.
              inputWord = inputWord.toLowerCase();                     //converts the 'inputWord' to all Lower Case
              for(int i=0;i<inputWord.length(); i++) {                //removes punctuation marks
                   char ch = inputWord.charAt(i);          
                   if (ch>='A' && ch<='Z' || ch>='a' && ch<='z'){      //checks if character is in the alphabet
                       shortWord += ch;                                //and if it is, it concatenates it to 'shortWord'
                   }                                                             //end if statement.
               }                                                                  //end for statement.
              System.out.println(); I'll give 8 Stars to Ravi_Gupta and 2 Stars to Flounder.

Similar Messages

  • How do I remove spaces and special characters from the file name during rendering?

    I understand that I can set LR_renamingTokensOn to true, but I would like to replace all spaces in the file name with an underscore and remove characters not in the range A-Z and 0-9. What's the easiest way to achieve this?

    local photo = catalog:getTargetPhoto()
    local sesn = LrExportSession {
        photosToExport = { photo },
        exportSettings = {
            -- ... (determine from export preset) - whatev you want, just be sure you set export directory: LR_export_destinationPathPrefix
            LR_tokens = "{{custom_token}}",
            LR_tokenCustomString = LrPathUtils.removeExtension( photo:getFormattedMetadata( 'fileName' ) ):gsub( "[ %c]", "" ) -- remove spaces and control characters
    sesn:doExportOnNewTask()

  • Remove spaces and special characters from a form field

    Hi,
    I am tragically new to all of this, but am trying to create a form in Adobe Acrobat 9.  I am trying to use a Custom Format script to take inputs in a form field and automatically remove spaces and special characters (hyphens specifically).  For example, if a user inputs "RAN-99 06" I would like it to change to "RAN9906."  I found this script that will not let users input special characters
    if (!event.willCommit) {
        event.change = event.change.replace(/[\$#~%\*\*\^\-\(\)\+=\[\]\{\};\"\<\>\?\|\\\!]/g, "");
    And that's okay, but I can't figure out how to disallow spaces.  Also, the perference would be for a script to allow users to input the data as they like, but to clean it up after they leave the text field.
    Thanks in advance!

    From the description, I assume that the script is currently in the Keystroke event. In fact, that would be a most logical way to have it; simply ignore anything unwanted when entered.
    If you want to allow the user to enter anything, but "clean it up" when done, you would place your code in the Validate event. You will have to adjust your Regular Expression so that it works globally, but that's the whole difference. This will change the value.
    Note that you can also enter the code into the Format event. However, that would only change the visual representation of the value, but internally, the value would remain as entered.
    Hope this can help.
    Max Wyss.

  • Need to remove sixth and remaining characters from a PDF file name

    Typical file name:
    1925a - SomeotherTextHere.pdf
    Need to remove everything after and including the "-" symbol or the sixth position.
    I've tried this but to no avail:
    var filePath = this.path.replace(this.documentFileName,"");
    var newFileName = this.documentFileName.substring(0,6);
    this.saveAs(filePath + newFileName);
    Thanks in advance,
    Russell

    You were right......but a quick question. Why does this work without it? Thanks again!!!
    var filePath = this.path.replace(this.documentFileName,"");
    var newFileName = this.documentFileName.substring(1);
    this.saveAs(filePath + newFileName);

  • Safari showing weird characters and letters and LOTS of whitespaces!!

    Hi!
    I've installed Mac OS X Snow Leopard (nice program), anyway - Safari has been messed up now. It is showing lots and lots of whitespaces and just single letters like k s Ss and that kind of stuff, this picture show an email I've read (http://i940.photobucket.com/albums/ad250/Dwatten/Skrmbillede2009-09-28kl164217.p ng)
    What am I supposed to do??
    -Thanks in advance
    Dennis

    By the way - I've installed them by dragging them into the SYSTEM font folder I didn't know I oculd just double-click the font and then it would be installed into the font book.. But can I reinstall the font book and all system fonts back to SYSTEM DEFAULT?
    I would really like to clean up my fonts one time for all instead of deleting some and then manually putting the ones I need into the font book..

  • I have FF and win7. Fonts turn to weird characters at more then 75% zoom when the checkbox "allow webpages to choose their own fonts" in the contents option advanced is checked, when forced to calibri this behaviour doesnt occur An aexample of that is

    I have FF and win7. Fonts turn to weird characters at more then 75% zoom when the checkbox "allow webpages to choose their own fonts" in the contents option > advanced is checked, when forced to calibri this behaviour doesnt occur
    An aexample of that is the product title on the product of this website:
    https://www.xstreetsl.com/modules.php?name=Marketplace&file=item&ItemID=2424553
    While switching to double check this I just saw that this also happens in this very window in wich i am typing my question now. If i copy and paste this text to for example notepad or anything else, it shows up like normal text.
    == This happened ==
    Every time Firefox opened
    == i installed firefox on win 7

    This issue can be caused by the bitmap version of the Helvetica or Geneva font or another (bitmap) font that can't be displayed by Firefox in that font size.
    Firefox can't display that font in the specified size and displays gibberish instead.
    You can test that by zooming out (View > Zoom > Zoom Out, Ctrl -) to make the text smaller.
    Uninstall (remove) all variants of that not working font to make Firefox use another font or find a True type version of that font that doesn't have the problem.

  • Why does a find and replace method remove whitespace?

    I have method that searches for a string in a FM document and replaces it with a variable. If for example, there was a string foobar that I wanted to replace with the variable barfoo. Then, I expect this text:
    Lorem ipsum dolor sit amet, foobar consectetur adipiscing elit. Vivamus sed purus urna, ac tristique tortor. Nam auctor tellus non enim pulvinar a vestibulum neque tincidunt.
    To be changed to this text:
    Lorem ipsum dolor sit amet, barfoo consectetur adipiscing elit. Vivamus sed purus urna, ac tristique tortor. Nam auctor tellus non enim pulvinar a vestibulum neque tincidunt.
    However, while the text does do the replace it also removes the whitespace between the variable and the text that appears right after the variable so it actually looks looks like this:
    Lorem ipsum dolor sit amet, barfooconsectetur adipiscing elit. Vivamus sed purus urna, ac tristique tortor. Nam auctor tellus non enim pulvinar a vestibulum neque tincidunt.
    Why is the find and replace method removing the whitespace and how do I prevent that from happening? The method is provided below.
    function FindAndReplaceString(pDoc, findString, replaceVariable)
        if (typeof pDoc != 'undefined'&&typeof findString != 'undefined'&&typeof replaceVariable != 'undefined'&&pDoc.ObjectValid()&&findString.length>0&&replaceVariable.length>0)
            var vVarFmtStatus=checkVarFmStatus (pDoc, replaceVariable);
            if (vVarFmtStatus=='In Doc')
                var tr = new TextRange();
                var findParams = new PropVals();
                var frame = pDoc.MainFlowInDoc.FirstTextFrameInFlow;
                var restoreTR = pDoc.TextSelection;
                tr.beg.obj = tr.end.obj = frame.FirstPgf;
                tr.beg.offset = tr.end.offset = 0;
                findParams = AllocatePropVals(1);
                findParams[0].propIdent.num = Constants.FS_FindText;
                findParams[0].propVal.valType = Constants.FT_String;
                findParams[0].propVal.sval = findString;
                tr = pDoc.Find(tr.beg, findParams);
                var vLoopCounter=0;
                while(FA_errno === Constants.FE_Success&&vLoopCounter++< 1000)
                    pDoc.TextSelection = tr;
                    pDoc.Clear(0);
                    var newVar = pDoc.NewAnchoredFormattedVar(replaceVariable, tr.beg);
                    var varLength = newVar.TextRange.end.offset - newVar.TextRange.beg.offset;
                    tr.beg.offset += varLength;
                    tr = pDoc.Find(tr.beg, findParams);
                if (vLoopCounter>0)
                    Log (vLogFileName, 'In the document \''+pDoc.Name+'\', the string \''+findString+'\' was replaced with the variable \''+replaceVariable+'\' '+vLoopCounter+' times.\n')
                if (vLoopCounter>1000)
                    recordErrors (vErrorLog, 'ERROR: In the document "'+pDoc.Name+'", the find and replace operation was stopped after executing '+vLoopCounter+' times. The term being searched for is "'+findString+'" the replacement variable is "'+ replaceVariable+'".')
                pDoc.TextSelection = restoreTR;
                pDoc.ScrollToText(restoreTR);
                } else {
                    recordErrors (vErrorLog, 'ERROR: The find and replace operation failed because the variable '+replaceVariable+' does not exist in the following doc: '+pDoc.Name)
            } else {
                recordErrors (vErrorLog,'Invalid or unitialized parameter passed to function FindAndReplaceString')

    Hi,
    Not at the moment. Please post in http://forums.adobe.com/community/muse/ideas so other users can vote on the feature request.
    Thanks,
    Abhishek

  • My Mac won't read cyrillic in certain files and displays instead weird characters like this: "–í–µ-Ç–µ-Ä –ø-Ä–æ–¥–∏-Ä–∞–µ-Ç –¥–æ –∫–æ-Å-Ç–µ–π." Any ideas why this might be or how I can solve it?

    Yesterday I extracted the subtitles of an MKV file to try and print them. Unfortunately, when I open the .srt file with any text processor, it displays weird characters like the ones included in the title:
    "–û–±—ã–≤–∞—Ç–µ–ª–∏ –ø–µ—á–∞–ª—å–Ω—ã.
    –í–µ—Ç–µ—Ä –ø—Ä–æ–¥–∏—Ä–∞–µ—Ç –¥–æ –∫–æ—Å—Ç–µ–π."
    I thought this had to do with it being an .srt file, but just now I encountered the same problem with an Excel file.
    Any ideas why this might be or suggestions as to how to solve it?
    Thanks in advance,
    Mario

    It looks like an encoding problem.  You should try opening the file in a text editor where you can choose one of the various possible cyrillic encodings (utf-8, koi8-r, iso-8859-5, win-1251, MacCyrillic)

  • Weird Characters and Cyberduck

    Hi,
    I'm trying to get rid of weird characters on my web page when I do 'enter' to skip a line and when I use '
    What settings do I need to use with Cyberduck as an ftp client?
    Thanks!

    Hi, I'm having the same problems, when I use tab or carriage returns I get an annoying A with a circumflex. I've tried switching off ISO encoding in Fetch, and looking at the page in UTF-8 but to no avail. The site looks fine from my local hard drive, so can only surmise it's something in the code.
    my url is
    www.brandtacticians.com/site2/
    here's a sample of some of the source code
     
    Tel         +447971 407951
    Fax        Get with it, gramps
    email      brian at

  • Offline approval - weird characters in Outlook

    Hi all,
    We're on SRM 5.0, Server 550, SP12.
    Scenario: offline approval of Shopping Carts
    After running report RBBP_NOTIFICATION_OFFAPP, approver is getting an e-mail in Outlook 2003 with some weird characters:
    **START**
    Â
        The following requires processing:
    Â
        1 . Approve shopping cart of Shopper with value 64,78 USD
       
    Â
    Â
        Use the following link to log on to the system and carry out the approval online:
        Log on
    Â
    Â
        To approve or reject directly from this e-mail, select one of the following links:
    Approve by E-mail   Reject by E-mail   Â
    **END**
    When I look at the same message in , these characters are not visible; but there seem to be spaces/blanks in those spots. Looks like Outlook is substituting spaces for some other character.
    Also, there're some extra blank lines, which we would like removed.
    Any ideas how to get rid of the unwanted characters and unnecessary lines, besides BAdI implementation?
    Cheers,
    Serguei

    Hi,
    Please check the foll note:
    Note 1100912 - E-mail messages for work items with incorrect line break
    Also,sometimes some junk characters are inserted into the offline mail if the required services(for the generation of mail ) are not active in transaction SICF.
    Please see whether the following path is active in SICF:
    SAP/BC/BSP/SAP/SMART_FORMS/DEFAULT.CSS
    If the above service is not activated,then activate that and re-test.
    Last option would be to implement the BADI BBP_OFFLINE_APP_BADI (method ~MAIL_DATA_GET) to remove the unwanted characters.
    BR,
    Disha.

  • Weird characters in g++ output

    When using Arch and ssh/xterm to remotely logging into an Ubuntu machine (university lab computer)  to run g++, the complier output (when there's a compile error) has an accented character "a hat" (i.e. the character "a" with a caret symbol above it) in place of all function and variable names .
    For instance, it will output:
    file.cc : In function <a-hat symbol>
    file.cc:19: error: <a-hat> was not declared in this scope.
    when it should have outputted:
    file.cc : In function main
    file.cc:19: error: idx was not declared in this scope.
    NOTE:  I don't know how to enter special characters in a post, so I entered <a-hat> instead of the actual special character.
    Now, it doesn't happen when I log into the Ubuntu machine from another Ubuntu machine.  It only happens when the client is Arch.  I am 99% certain that this is a problem with Ubuntu and not Arch.  But, I don't have root on the Ubuntu machine because it's the school's computer, so I can't fix it.
    Does anyone know if there's something I can try on the Arch box that will fix this display problem?
    EDIT:  Sorry, I should've posted this in the Workstation thread maybe.  Admins, please kindly move it if you see fit.
    Last edited by battra (2007-06-06 03:55:20)

    grepper and Tucos in #conky solved the issue for me.  Apparently, the "weird characters" was a color code.  I had to pipe:
    sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"
    in conkyrc to remove color codes.

  • Some questions on whitespace and &

    Dear all,
    I have some questions on whitespace and & that need you kind help:
    1. Except /n /t /r and space, is there any characters that are whiteSpace characters?
    2. When parsing XML document, when the ignorableWhitespace() method is called? Will it be called from characters() ?
    e.g. Where the white space after <a> is called, and where is the white space between test1 and test 2 indied <b> is called?
    <a>
       <b>test1 test2</b>
    </a>  3. When the & should be escaped in a well-formed (or validated) XML file by replacing &?
    It should be excaped in any element content, such as <b>test1 & test2< /b> - except for <![CDATA[ section?
    It should NOT always be used in attributes? e.g. <a b="test1 & test2"/>  - has to do escaped by entity & - am I right?
    Thanks!
    Thanks
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Thanks DrClap.
    >
    2. When parsing XML document, when the
    ignorableWhitespace() method is called? Will it be
    called from characters() ?It will be called when the document has a DTD and the
    parser is a validating one that is actually
    validating, when the parser sees whitespace that is
    not part of a DTD element. It will not be called from
    characters() because that is a method that you write.I wrote a contentHandler and using Xerces parser to parse an XML document. When I set validating feature to false, I found that for:
    <a>
       <b>test1 test2</b></a>The white space between <a> and <b> (including newline) is actually called from characters(), not in ignorableWhitespace(). So does this mean that if validating - white space is always called from ignorableWhitespace(), and if not validating, if it is always called from characters()?
    >
    3. When the & should be escaped in a well-formed(or
    validated) XML file by replacing &? The XML Recommendation says "The ampersand character
    (&) and the left angle bracket (<) may appear
    in their literal form only when used as markup
    delimiters, or within a comment, a processing
    instruction, or a CDATA section. If they are needed
    elsewhere, they must be escaped using either numeric
    character references or the strings "&" and
    "<" respectively."So in this sense, both & in <b>test1 & test2< /b> and <a b="test1 & test2"/> is illegal unless replacing them by & - right? What does the markup delimiters mena in above XML Recommendation ? Example?
    Thanks!

  • Japanese lyrics shown on iPhone become weird characters after some number of plays

    I put in lyrics for my Japanese songs both the kanji/kana and romaji. There have been no problems before this. But somehow I suppose after the newest iTunes released I added some new songs and there were two of them that I added lyrics into them. At first their lyrics were shown properly on my iPhone screen. But after some time the kanji/kana became some weird characters. I checked the lyrics in iTunes and there seemed to be no problems at all with my lyrics. I needed to delete the song from both my phone and my iTunes library and re-add then re-synced it again. (just deleting the song from the phone and then re-synced it didn't help.) Then again, today the lyrics became weird again. I don't really understand. It would become very annoying if this keeps going on. I would appreciate any advice and help. Thank you very much.

    I just tried this with my iPhone 4 and it also didn't work.  This is how it failed:
      - Select "shared".
    - The "pie" start to grow, got to about 1/3, then crashed without
        bringing in the shared content.
    - After that, the library appeared in list, but I couldn't select
        it at all anymore.
    Then I tried it with my iPad.  The pie got to the same point, sat
    there for a long time, then completed and worked fine.
    I did a hard reset of the phone and tried again, this time it
    behaved like the iPad and worked fine.
    Not sure whether it was the hard reset or whether sharing with
    another device "woke something up", but in any event it works
    now and I can't get it to break again.
    Note, I only use sharing for movies, since I have Music Match
    (which works *great* for me, even on 3G).
    Specs:
      Sharing: 2.7 GHz iMac i5, OS 10.6.8
      Clients: iPhone 4
                  4th gen iPad
    Everything (including iTunes) patched to the latest.

  • Strange-shaped fonts and unreadable characters in the PDF file

    Hello,
    A colleague of mine printed out a PDF file that I generated. Some of the fonts in the printed PDF file appear out-of-shape (slightly squiggly but still readable). These fonts are in plain body text and some of the heading styles. In addition, unreadable characters appear for fonts in the PDF where a keyboard input character format was specified in the source (in Framemaker a different character format can be specified for individual words within a paragraph format).
    He printed this PDF file a total of eight times. For the first five times there were no issues, but in the last three times the problems occured.
    He printed the files from the same printer and some of the printing was with the PCL profile, while others were with the PS profile.
    My colleague viewed the files using Adobe Reader 8 running on Windows XP.
    My PC is also Windows XP. The document source is FrameMaker 7.2. When generating the file, I used Acrobat Distiller 8.0. It is compatible with Acrobat 5.0 (PDF 1.0). The Acrobat Reader I have on my PC is Acrobat 8.0.
    Thanks,
    Ken

    I'm using acrobat 8.1.0 and I believe I have the same problem as Ken.
    However, I have a question. If the fonts simply weren't installed, wouldn't they also appear as weird characters when looking at a soft copy in acrobat? Why would the problem only occur when printing?

  • Remove all non-number characters from a string

    hi
    How i can remove all non-number characters from a column ? for example , i have a column that contains data like
    'sd3456'
    'gfg87s989'
    '45/45fgfg'
    '4354-df4456'
    and i want to convert it to
    '3456'
    '87989'
    '4545'
    '43544456'
    thx in adv

    Or in 9i,
    Something like this ->
    satyaki>
    satyaki>with vat
      2  as
      3    (
      4      select 'sd3456' cola from dual
      5      union all
      6      select 'gfg87s989' from dual
      7      union all
      8      select '45/45fgfg' from dual
      9      union all
    10      select '4354-df4456' from dual
    11    )
    12  select translate(cola,'abcdefghijklmnopqrstuvwxyz-/*#$%^&@()/?,<>;:{}[]|\`"',' ') res
    13  from vat;
    RES
    3456
    87989
    4545
    43544456
    Elapsed: 00:00:00.00
    satyaki>
    {code}
    I checked this with minimum test cases. It will be better if you checked it with other cases.
    Regards.
    Satyaki De.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Maybe you are looking for

  • Acrobat 7 open file locations issue

    Using Adobe Acrobat 7.  When trying to open the file from a drive the message,  "There was an error opening this document. Path does not exist." appears.  I can open it fine from the C:. None of the other drives show under File/Open.  Using Windows 7

  • How can I find and remove an unused font embedded in PDF exported from a book?

    The font (Myriad Pro) was the original [Basic Paragraph] font in the indd files, but I need to replace it with a different (approved) font. MP is no longer found by Find Font in any of the indd files in the book. It is not used (that I can find) in t

  • How  to maintain the entries using table maintanance??

    Hi, I have created a Ztable. and I have created table maintanance generator, then attached the table to a Tcode. but I am unable to maintain the entries in table maintanance?? Can anyone help me out Regards Devi

  • Help!! Address Book and iCal don't open

    When I try to open Address Book or iCal they won't open. I've reinstalled the latest OS update (10.4.10) and still they won't open. I urgently need to access some of the details in my address book - does anybody have idea why they won't open? Any hel

  • The audio service is not working/running.

    Hi, I have been having some problems with my audio recently. My laptop is a 3 week old HP Pavilion 15-p189sa displaying the sign "the audio service is not running". I have read nearly all of the forums on this relating to this problem and have uninst