Replacing all word occurances in JEditorPane

Hello,
I need to replace all the word occurances in a JEditorPane.
I am doing it the following way
say for example the doc has the following text.
"The doument is having and was having the follwing text and will have more text ";
String s1= "having";
String replaceTxt "having having";
int index1 = 0;
try
HTMLDocument doc = ( HTMLDocument )jeditorPane.getDocument();
String source = doc.getText( index, doc.getLength() );
catch( BadLocationException bl )
for( int i=0; i<source.length(); i++ )
int index = source.indexOf( s1, index1 );
index1 = index + s1.length();
jeditorPane1.select( index, index1 );
jeditorPane1.replaceSelection( replaceText );
jeditorPane1.revalidate();
My problem is when i am inserting the same string twice i.e having having then it is going intoa loop.
Anybody any ideas.
Thanks.
REg,
suri

start inserting from the end of string.
First create an array of word offsets then start inserting from the end of this array.
best regards
Stas

Similar Messages

  • Letter A replaced all words in top bar and info boxes so I cannot read them. This soon after installing OS X Maverick, so I suspect this is related. Restart and Command-Control-P-R do not help.

    ? - Letter A has replaced letters of all words in top bar and  program boxes so I can read nothing, and therefore have no way to enter commands. This comes soon after installing OS X Mavericks, so I suspect this is related. Restarting and command-control-P-R have not helped. Can anyone suggest a cause?

    Back up all data.
    Launch the Font Book application and validate all fonts. You must select the fonts in order to validate them. See the built-in help and this support article for instructions. If Font Book finds any issues, resolve them.
    From the application's menu bar, select
    File ▹ Restore Standard Fonts...
    You'll be prompted to confirm, and then to enter your administrator login password.
    Boot in safe mode to rebuild the font caches. Boot again as usual and test.
    Note: If FileVault is enabled, or if a firmware password is set, or if the boot volume is a software RAID, you can’t boot in safe mode. In that case, ask for instructions.
    Also note that if you deactivate or remove any built-in fonts, for instance by using a third-party font manager, the system may become unstable.

  • How can I Find/Replace a word on all cast members together rather than one at a time?

    I currently use Director 11.5.9 with Windows 7 64 bit
    I have some director movies I programmed years ago.  I included the file extension .dir when I used "go to movie" statements (I didn't know any better at that time).  For example, I would write, go to movie "alpha.dir".  I have now updated those movies to Director 11.5.9 and want to protect them by updating them to .dxr movies.  Obviously, the code "go to movie name.dir" won't work any more.  I need to take out the .dir extensions from every occurance in those movies.  Most all of them are cast scripts on buttons.  A few of them appear in score scripts.
    In searching this forum, I did find some tips for search/replace on ALL cast scripts, but when I attempted to follow them I did not find the options they suggested on the drop down menus.
    Can someone tell me the steps for going into a Director movie and telling the Find and Replace function to replace ALL occurences of ".dir" in Cast Scripts with ""?
    Currently, I am having to find them manually and replace them one at a time.  There are a LOT  movies with a LOT of occcurences of .dir, so this is far too slow.  I'm sure it can be done more efficiently.
    Any help than anyone can provide will be greatly appreciated.  I have a project that is coming due very soon and I don't want to delay it if possible.
    Dewey

    When you open any script in this movie and press CTRL+F it should open a search-and-replace text dialog with a "Replace all" button/option that does exactly what you are asking for - unless I've misunderstood.

  • Replace all misspelled words

    On my iMac, I'm using Pages. I want to know how to replace all the misspellings of a particular word with the correct spelling. For example, the word is underlined in red because it is misspelled. When I correct it, I would like to correct all other of the same words that were misspelled in the same way throughout a particular document. I'm using OSX 10.9.3
    I tried to use Edit  and chose Substitutions. I want to "Replace All" but I can't figure out how to tell the program with which word I want to "Replace All."
    I also did two taps on my trackpad to get a suggested spelling. I can't figure out how to choose the correct spelling and tell the program to "learn spelling" at same time. I can only choose one option. If I elect "Learn Spelling" it is going to learn the wrong spelling! How to choose the correct word and then tell the program to learn that spelling and correct all the rest of the words (same word) in my document???

    If you are referring to Pages v5.2, use Edit > Find. In the resultant dialog, click the gear selector and choose Find & Replace. Replace All is one of the button choices.
    Try Edit > Spelling and Grammar > Show Spelling and Grammar (command + : shortcut) to get a dialog that shows suggested spellings, learn, and define buttons.

  • Is there a "Replace All" command?

    This seems like a no-brainer....  I found the  "Ctrl+F" find and replace, but it only replaces a sindle instance of a text string.  I also found the complext find dialog.  It lets you find all occurances, but (apparently) you cannot do replaces from there.  Is it possible to do a "Find and Replace All" in my PDF? 
    Many Thanks.
    Win 7, Acr XI.

    The more you think of Acrobat as being like Word, the more frustrating it will get. Text editing is a desperate last resort, not a normal process.

  • Purchased songs in the past then recently purchasd new songs,  but the new purchases replaced all of my old purchases.  How can I retrieve my old purchases?  Cannot find them in any of my playlists.

    Purchased songs in the past then recently purchasd new songs,  but the new purchases replaced all of my old purchases.  How can I retrieve my old purchases?  Cannot find them in any of my playlists.

    If you purchased all of the songs through itunes store, please follow these steps:
    1. Open up Itunes and Click on Itunes Store
    2. Once you're in the Itunes Store look to right side of the screen and you should see the word "purchased". Click purchased and you'll be sent to a purchase screen.
    3. Click on "All Songs" and then it will show all the songs you've downloaded. From there you just hit the button that looks like a cloud with an arrow on it, and it will download all the songs all over again.

  • How do I find and replace a word in PDF?

    How do I find and replace a word in PDF?

    In the Find window (Ctrl+F) there's an option to replace the searched text.
    This is in Acrobat XI, and there's no Replace All-function.
    On Thu, Jan 15, 2015 at 4:27 PM, claireb88184899 <[email protected]>

  • How can I find and replace multiple words at once?

    I need to be able to find and replace words into queens English. For example, I need to replace all instances of "color" with "colour," "tire" with "tyre" etc.
    I'm new to scripting, so simple answers would be appreciated :)

    Hi hobs707,
    Please use the below code for your required output:
    Replace ("color", "colour")
    Replace("tire", "tyre")           
    //Replace("hobs707", "hobs007")     just copy and paste and edit the contents as your wish
    function Replace(input, output)
    app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
    app.findTextPreferences.findWhat = input;
    app.changeTextPreferences.changeTo = output;
    app.activeDocument.changeText();
    If the above answer is correct please provide Correct Answers for me.
    Regards
    Beginner

  • Replace \n with br in JEditorPane

    Hi,
    I use a JEditorPane to edit some HTML-text. The problem is that the return-key produces a "\n" and not a "<br>". First I tried to replace all "\n" with "<br>" but the problem is that JEditorPane formats the source code on several lines. Eg:
    <table><tr><td>some text</td></tr></table>
    becomes:
    <table>
      <tr>
        <td>
          some text
        </td>
      </tr>
    </table>So I cannot say which newline character is from user input and which from the source code formatting.
    Now I thought to replace the action performed when the return-key is pressed, so that JEditorPane produces a "<br>" instead of "\n".
    What is the correct way to do that?
    Thanks for your help.
    Greez
    Puce

    Here is a small example:
    * EditorPaneTestFrame.java
    * Created on 17. Juni 2003, 11:21
    package test;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.text.*;
    * @author  puce
    public class EditorPaneTestFrame extends JFrame {
      private static final String insertHtmlBreakAction = "insert-html-break";
      /** Creates new form EditorPaneTestFrame */
      public EditorPaneTestFrame() {
        initComponents();
        setSize(400, 600);
      /** This method is called from within the constructor to
       * initialize the form.
       * WARNING: Do NOT modify this code. The content of this method is
       * always regenerated by the Form Editor.
      private void initComponents() {
        jPanel2 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jSplitPane1 = new javax.swing.JSplitPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        jEditorPane1 = new javax.swing.JEditorPane();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        addWindowListener(new java.awt.event.WindowAdapter() {
          public void windowClosing(java.awt.event.WindowEvent evt) {
            exitForm(evt);
        jButton1.setText("Show Source");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton1ActionPerformed(evt);
        jPanel2.add(jButton1);
        getContentPane().add(jPanel2, java.awt.BorderLayout.SOUTH);
        jSplitPane1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
        jSplitPane1.setResizeWeight(0.5);
        jEditorPane1.setContentType("text/html");
        jScrollPane1.setViewportView(jEditorPane1);
        jSplitPane1.setTopComponent(jScrollPane1);
        jScrollPane2.setViewportView(jTextArea1);
        jSplitPane1.setBottomComponent(jScrollPane2);
        getContentPane().add(jSplitPane1, java.awt.BorderLayout.CENTER);
        pack();
      private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
        jTextArea1.setText(jEditorPane1.getText());
      /** Exit the Application */
      private void exitForm(java.awt.event.WindowEvent evt) {
        System.exit(0);
       * @param args the command line arguments
      public static void main(String args[]) {
        new EditorPaneTestFrame().show();
      // Variables declaration - do not modify
      private javax.swing.JButton jButton1;
      private javax.swing.JEditorPane jEditorPane1;
      private javax.swing.JPanel jPanel2;
      private javax.swing.JScrollPane jScrollPane1;
      private javax.swing.JScrollPane jScrollPane2;
      private javax.swing.JSplitPane jSplitPane1;
      private javax.swing.JTextArea jTextArea1;
      // End of variables declaration
    }Note that here typing "ENTER" results in "<p></p>" and not in "\n" as in my work. I couldn't figure out why.

  • Search for all words in a table column that any of the words start with a certain letter

    I have products table. Each row has a Description which may have a few words within it. I wanted to know if it's possible to search through it and find all descriptions that have match the search. But, I want it to consider it a match even if it's not the
    first word of the description, but rather the start of any word in the description.
    For example:
    Descriptions
    Nice Casual Gloves(This should show up, and although it's not in the very beginning of the description it's at the beginning of a new word.)
    Nice Dressy Gloves(This should show up, and although it's not in the very beginning of the description it's at the beginning of a new word.)
    Great Dresses (This should show up)
    Fancy Outerwear
    Glasses (This should show up)
    Shoes
    Sheer Stockings (This should not show up because although it has a "g" it's not in the beginning of a word.)
    Boots
    Galoshes (This should show up)
    I would want to search within this list Where Description like 'G%' but I don't want it to only get the descriptions that start with "g" at the beginning of the description, but rather any "g" at the beginning of any word. I do not want
    to get all descriptions that have a "g" somewhere in the word (then I could just do WHERE DESCRIPTION LIKE '%g%'), rather only if it somewhere within the description but at the beginning of any word.
    Thank you so much
    Debra has a question

    The most perfect solution would be to get a CLR routine to either (a) Do a regular expression match, (b) Run a split routine at CLR speeds then do a simple LIKE, or (c) both (a) and (b).  If your requirements grow to handle more and more complex searches,
    you may have to do it that way eventually.
    However, like the other answers, here's a way to do it reasonably well given your current requirements.  You may have to tweak the REPLACE logic if you have frequent OTHER forms of word delimiters.
    Method:  Pull data; add space before and after original text; replace all common word separators other than space with a space (so for example, "(These pretzels)", "He said 'These pretzels are making me thirsty" and so forth would
    be replaced with a space before "The"; then do a Patindex (you could do with just a LIKE also) on the search string prefaced with a space.  Here's an example, stealing from table sys.messages just for ease of demonstration.
    With SampleData as
    Select top 100 *
    , ' ' + Replace(Replace(Replace(Replace(text, '"', ' '), '''', ' '), '/', ' '), '(', ' ') + ' ' as TextPlus
    from sys.messages
    where language_id = 1033
    Select TextPlus
    , patindex('% The%', textplus)
    from SampleData
    where patindex('% The%', textplus) > 1
    Same logic, in the most concise format:
    Select top 100 Text
    from sys.messages
    where language_id = 1033
    and ' ' + Replace(Replace(Replace(Replace(text, '"', ' '), '''', ' '), '/', ' '), '(', ' ') + ' ' like '% the%'

  • Replace all

    Hi there,
    i got this codes online for replacing a word in textarea . The problem is it only replace the first word it match, while other same word still remain un-replace.how to modify it so that it can replace all the particular words that i wantto replace in the textarea.
    Document doc;
    doc=text2.getDocument();
    SimpleAttributeSet set= new SimpleAttributeSet();
    String str1 = JOptionPane.showInputDialog(null,"Enter the word to be replace:","replace",JOptionPane.QUESTION_MESSAGE);
    String str2= JOptionPane.showInputDialog(null," Replace the word with :","replace",JOptionPane.QUESTION_MESSAGE);
    int index=0;
    if(str1!="" && str2!="")
    try{          
    index=text2.getText().indexOf(str1);
    doc.remove(index,str1.length());
    doc.insertString(index,str2,set);
    }catch(BadLocationException b){
    JOptionPane.showMessageDialog(null," Word not found !","Not Found",JOptionPane.ERROR_MESSAGE);
    }

    Sorry, hit the post button too soon
    Document doc = text2.getDocument();
    String replaceThis = JOptionPane.showInputDialog(null,"Enter the word to be replace:","replace",JOptionPane.QUESTION_MESSAGE);
    String replaceWith = JOptionPane.showInputDialog(null," Replace the word with :","replace",JOptionPane.QUESTION_MESSAGE);
    SimpleAttributeSet set= new SimpleAttributeSet();
    if(!replaceThis.equals("") && !replaceWith.equals(""))
      if(text2.getText().indexOf(replaceThis) == -1)
         JOptionPane.showMessageDialog(null," Word not found !","Not Found",JOptionPane.ERROR_MESSAGE);
      else
        while(text2.getText().indexOf(replaceThis) != -1)
          try
            int index=text2.getText().indexOf(replaceThis);
            doc.remove(index,replaceThis.length());
            doc.insertString(index,replaceWith,set);
          catch(BadLocationException e)
            // should not happen
            e.printStackTrace();
    }

  • Set fill color of all words in list

    I want to change the fill color of all words in a document from a provided list of terms.
    For example, the following script works perfectly in Quark:
    set theIndexList to {"3rd Class", "4th class", "4th Class", "5th class", "5th Class", "7 lines of management/defense", "7 lines of management/defense", "7 Lines Of Management/Defense", "abalakov anchor", "Abalakov anchor", "Abalakov Anchor", "adze", "Adze", "Adze", "alpine rock", "Alpine rock", "Alpine Rock", "anchor", "Anchor", "Anchor"}
    tell application "QuarkXPress™ 4.11"
         tell document 1
             tell story 1
                 repeat with currentWord in theIndexList
                     try
                         set (the color of every text where it is currentWord) to "Green"
                     end try
                 end repeat
             end tell
         end tell
    end tell
    The purpose of this script is to highlight words for later indexing. I need to read through the document, see words someone else has chosen for indexing, then add them selectively to the index.
    InDesign CS, Mac OSX 10.3.9

    >It's not a question of which program has more complex object model
    Actually, it is largely. Search and replace in Quark relied on a combination of AppleScript whose clauses and a slightly odd definition of its text class. This made searches very simple, but it also meant they were restricted in what they could do. InDesign uses a more complex model, and exposes the full find/change engine; it's not as straight-forward, but it lets you do things that wouldn't be possible if they stuck to the whose clause approach.
    In fact you can use whose clauses similarly in InDesign, with one catch: InDesign has a different definition of what constitutes text (there is only 1 text per story), so it will only work if you're looking for one of the classes like words, lines, text style ranges, etc.
    I hesitate to rewrite the the js version in AS for CS because I don't have CS installed here. And there's an oddity involving color searches that makes it a bit more complicated than it should be. But it's very similar to the javascript.
    > Because this is an AppleScript forum
    I'm not sure what gave that impression, but it's far from so.

  • Replace Microsoft Word strange characters

    I'm trying to create a function to replace all the strange
    characters that come from Microsoft Word, but it doesn't seem to
    work. Any thoughts? Thanks!
    function replaceWordCharacters(str) {
    str = replace(str, chr(8217), chr(39), "all");
    str = replace(str, chr(8216), chr(39), "all");
    str = replace(str, chr(8220), chr(34), "all");
    str = replace(str, chr(8221), chr(34), "all");
    str = replace(str, chr(8211), "-", "all");
    str = replace(str, chr(13), "<br/>", "all");
    WriteOutput(str);
    return str;
    Eric

    Check out this UDF:
    http://www.cflib.org/udf.cfm?ID=725

  • Substitutions Replace All

    Since I like to output manuscrupts to ePUB for reading in iBooks, I prefer to have typographical quotation marks—smart quotes—on. Pages 5's parity with Pages for iOS made it more difficult to globally search-and-replace ordinary quotes (inch marks) with smart quotes from the Find & Replace dialog. (The crippling of the Find & Replace even more is a subject for another rant ) But it seemed Pages 5 has the answer in its Show Substitutions submenu.
    In the help, it says:
    Choose Edit > Substitutions > Show Substitutions (the Edit menu is at the top of your computer screen).
    In the Substitutions window, select the Smart Quotes checkbox.
    Choose a quotation mark style from each of the pop-up menus.
    Click a button to replace all occurrences of quotation marks in the document, or just in the selected text.
    Which I thought means if I have straight quotes and double-dashes, hitting "replace all" or "replace in selection" will convert them to curly quotes and em dashes.
    But it doesn't.
    So far as I can tell, nothing happens.
    Knowing that a lot of this is actually shunted into OS X's Text preferences, I tried making sure the Text preferences were set properly, quit all apps, restarted, opened Pages, opened a new document, typed in a test sentence with straight quotes and double-dashes, and then did the above Help procedure.
    Nope. Still nothing happens.
    I hope this is a bug and not another "refinement". I reported it as a bug.
    This wouldn't matter on documents edited on the Mac, since typing smart quotes and em dashes still work. Moving around from Pages on iOS, however—where getting to the correct quotes is a bit of a chore—I liked being able to do a global "smartify my quotes" on Pages on Mac. But like I said, can't seem to do that anymore—and the Help seems to say that I should, using the Substitutions dialog.
    Have you gotten this to work? Have I misinterpreted what the Substitutions submenu and dialog is supposed to do?

    A workaround, of sorts. After pasting large amounts of text (full of straight quote marks and straight apostrophes) into Pages documents I, too, have tried and tried to convert to smart quotes, only to be frustrated. (I also spent quite a bit of time on the phone in November 2014 with a Pages tech support person, and he could not provide an answer. He promised to pass this on to the Pages team. This is where you start holding your breath...) Here is my workaround until (if) Apple fixes this. You are going to groan when I say this, but if you have Word on your Mac simply copy and paste the text into Word. (Perhaps you may find another word processor that does the same thing.) There the conversion is quick and simple. Then paste it back into Pages. I happen to have an older copy of Word because I was forced to start using Pages when the version of Word would not utilize the Retina display on my new Power Book an everything was fuzzy.

  • REGEXP_REPLACE - replace several words

    Hi,
    Can anyone tell me if it is possible to replace several words at once using regexp_replace?
    I would like to do something like
    update...
    set field = regexp_replace(str, 'val1|val2|val3', '1|2|3');val1 would be replace with 1
    val2 would be replace with 2
    val3 would be replace with 3
    Is this possible or not?
    Thanks,

    You can do it with a nested replace:
    -- Data:
    with t  as
      select 'abcval1def' str from dual union all
      select 'xxxval2def' str from dual union all
      select 'xxxval3def' str from dual
    -- Select
    select replace(replace(replace(str,
                                       'val1','1'),
                                       'val2','2'),
                                       'val3','3')
    from t;

Maybe you are looking for