Find the beginning / the end of the word appearing in the text.

I feel really stupid for asking this, but my brain doesn't seem to work at the moment and I can't find my old semester 1 examples.
While I can easily solve this C++ by trying to do it in Java is somewhat of a mystery. size_t found =, str.find (string::npos-> etc.)

Basically, I'm implementing a default highlighter. The words that I must seek as much as I KNOW appear only once in the Document or not at all.
Query SQL, SELECT, FROM, WHERE, etc.
I'm going to offshore an example I found here: [http://www.java2s.com/Code/Java/Swing-JFC/Anexampleofhighlightingmultiplediscontiguousregionsofatextcomponent.htm]
Who seeks the vowels in a document and highlights. So I thought it would be a simple switch so he could do what I wanted, but I've been plugging away at him for a few hours now and can not solve.

Would be much easier if String.contains (CharSequence cs) gave something more useful back a... whole Boolean value would be well :(

Sample is below anyway, to make it simple, I have a simple query in the text pane and only looking for the 3 words, select where.
Can someone tell me how would I say the method addHighlight() of the word found less?
import java.awt.BorderLayout;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;

public class MultiHighlight implements ActionListener 
{

     private JTextComponent comp;
     private String[] wordsToHighlight;

     public MultiHighlight(JTextComponent c, String[] words) 
     {
          comp = c;
          wordsToHighlight = words;
     }

     public void actionPerformed(ActionEvent e) 
     {
          // highlight 
          Highlighter h = comp.getHighlighter();
          h.removeAllHighlights();
          String text = comp.getText().toUpperCase();
          
          for (int i=0;i<wordsToHighlight.length;i++)
          {
               if (text.contains(wordsToHighlight))
               {
                    // find start, find end... ?
                    h.addHighlight(start, end, DefaultHighlighter.DefaultPainter)
               }
          }
     }

     public static void main(String args[])
     {
          JFrame frame = new JFrame("MultiHighlight");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          JTextArea area = new JTextArea(5, 20);
          area.setText("Select *\nFrom stuff s, more m\nWhere s.otherstuff = m.otherstuff.");
          frame.getContentPane().add(new JScrollPane(area), BorderLayout.CENTER);

          JButton b = new JButton("Highlight All SQL words");
          String[] wordsToLookFor = { "SELECT", "FROM", "WHERE" };
          b.addActionListener(new MultiHighlight(area, wordsToLookFor));
          frame.getContentPane().add(b, BorderLayout.SOUTH);
          frame.pack();
          frame.setVisible(true);
     }
}
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
int start = text.indexOf(wordsToHighlight);                    int end = start + wordsToHighlight[i].length();                    try {                         h.addHighlight(start, end, DefaultHighlighter.DefaultPainter);                    } catch (BadLocationException e1) {                         e1.printStackTrace();                    }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        

Tags: Java

Similar Questions

  • Find the text formatted in a paragraph

    Hello

    I have a problem with the search for a formatted text.

    I have a paragraph that contains two times a character style "Bold".

    For example:

    Lorem ipsum dolor sit amet, adipiscing elit computer. DUIs nisl eros, vehicula nec, elementum a nunc aliquam tincidunt.

    I want to find the text in bold and change.

    So, I'm looking for with the GREP code. + $ and style of character "Bold".

    If I click on find next, I get only the first character style but not the second.

    If I click Find Next again, I get the next character style in another paragraph. Not the second in the same paragraph.

    Can someone help me?

    Thank you very much!

    You asked to find a text in bold at the end of a paragraph with this request. Try it without the $

  • Find the text and place the eps images

    Hello

    I have a lot of eps in the folder (eps001.eps, eps002.eps), but manually find the text in indesign [[[eps001.eps]]] and place corresponding image folder can someone help me

    Kind regards

    Barro

    Try this,

    var file = myArtFolder ("/ C / / numbers /" ""); Figure folder path

    var myArtFilesList = myArtFolder.getFiles ();

    app.findGrepPreferences = app.changeGrepPreferences = null;

    app.findGrepPreferences.findWhat = ' \ [------[------[. +------]------]------]';

    found = app.activeDocument.findGrep (true);

    for (j = 0; j< found.length;="">

    var foundText = .silence found [j];

    for (i = 0; i<>

    {

    "var artFile = ' [[[" + myArtFilesList [i] .name + ' "]]]"

    if(artFile==foundText)

    {

    found [j].insertionPoints.item (0) concerned (file (myArtFilesList [i]));

    }

    }

    }

    app.findGrepPreferences = app.changeGrepPreferences = null;

    I did not delete the text "[[[eps001.eps]]]...". "using script, you test and eventually remove it by using grep.

    Vandy

  • need help to find the text that has been reduced from word document

    I cut and pasted the document in a grammar online editor; After that it was edited, I tried to copy / paste to the document word; some how the text has been lost

    I cut and pasted the document in a grammar online editor; After that it was edited, I tried to copy / paste to the document word; some how the text has been lost

    If that you cut is not available to paste, you're out of luck. It's is not just about anywhere you can get it from. You will need to go back in the premodifie file.

  • Find the text and apply the format paragraph tag in Framemaker 11

    Help!

    I am trying to automate the search text in a file FM11 and CE marking with a specific paragraph tag. Once it is, I want to be able to search for the same string again and delete it. The research will include wildcard characters. I'm moving Word files on and bring with manual numbering of paragraphs. Thus, when they arrive, they "2.3.4.5" before paragraphs for example. I want to search all of the numbers at the beginning of paragraphs, tag all those with the appropriate para format (starting a catalog) and then remove the manual numbering.

    At this time do us it manually, using find/replace and by using wildcard search strings to find (such as '\P[1-9]*.*.*.*[0-9]', which will find all the para numbering at the beginning of a paragraph 4-digit), then using the change option to paste to paste in a paragraph of the catalog tag. Then we repeat the same search and delete the text, leaving only the tag para to the number format. It works very well, but errors can occur if the search string in set incorrectly or if the numbers are not deleted (in this case, it is found on the next search and re-labeled incorrectly). For example

    I work for the Air Force collection of entries from the field and creating publications out of them, so there is no mobile profit here, just trying to be efficient. Any help is greatly appreciated!

    Thanks in advance

    b

    Hi Brian,.

    I guess right here because I've never done this before, but... In my view, there is definitely something wrong with your mission to find the property values. The way you wrote, you are trying to assign two properties to a single table space. That's why you need to remove these two lines to make him find work, because they are replacing the FindText property apparently. Here is my proposal for how it should be:

    findParams = AllocatePropVals (2);

    findParams [0].propIdent.num = Constants.FS_FindText;

    findParams [0].propVal.valType = Constants.FT_String;

    findParams [0].propVal.sval = searchString.

    findParams [1].propIdent.num = Constants.FS_FindCustomizationFlags;

    findParams [1].propVal.valType = Constants.FT_Integer;

    findParams [1].propVal.ival = Constants.FF_FIND_USE_WILDCARDS;

    In any case, let me point out again once it is a hypothesis and I did not test this. I am sure, however, that the solution is somewhere along this path.

    Russ

  • GREP - Positive look behind - find the text beyond the space

    I have a GREP in a paragraph with a positive Outlook style behind. This research finds the characters up to a space and apply a style, but applies style beyond a space.

    What should I include in my GREP search to find text following a space? TIA

    Right. He finds only upper case and lower case letters, while the game ends on what is not one of these. Do you want to match the end of the paragraph? You can use (?.)<>

    for two words use (?)<>

    for a game for one or two words (two if there are two, otherwise only one), try (?.)<=\#)[\l\u]+(\s[\l\u]+)? (not="">

  • Firefox can't find the text on the HTML table cells

    Firefox cannot find (Ctrl + F) the text inside HTML tables, as in
    http://www.dip-Badajoz.es/BOP/ventana_anuncio.php?id_anuncio=22714 & FechaSolicitada = 2008-02-20
    If you try to search "Solano", Firefox will not find any matches, but "Solano" is here. This works fine on Chrome, for example.

    Thank you

    I am also on Linux, but if I start a version of Firefox 6 via Wine the I don't have a problem with a search for "Solano".

    Start Firefox in Firefox to solve the issues in Safe Mode to check if one of the extensions of the origin of the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > appearance/themes).

  • Try to find the text import preferences (retainFormat)

    In my (model only) plugin wich only deals with custom data binding, I'm trying to find the preference of the user selected last for things like "retainFormat" for import files.

    What I want is my plugin to do exactly the same as when a text file is slipped on the desktop, but then my own source.

    Everything works fine, except for the options of 'IImportManagerOptions '.

    I can't find a way to get these. Who is available for the UI plugins?

    Anyone?

    Thank you!

    Hi Bart

    You have an example of using IImportManagerOptions in ExtendedLink sample.

    Because ExtendedLink is a plugin for model I guess it should also work in your case.

    Concerning
    Bartek

  • Find the text overflow

    Hello world

    Is there a script that helps find text with the text in overflow areas (as in indesign with overset text)

    OK, now that I see your document, I see the problem. My script has been fixed to ignore the unnamed stream, and your captions are flows without a name, which is fine. Here's the script updated to the:

    var doc = app.ActiveDoc;
    var flow = doc.FirstFlowInDoc;
    
    while (flow.ObjectValid()) {
    
        var textFrame, subCol;
    
        // Get the last TextFrame and its last Sub Column.
        textFrame = flow.LastTextFrameInFlow;
        subCol = textFrame.LastSubCol;
        if (subCol.Overflowed === 1) {
            alert ("TextFrame is overflowed.");
        }
        flow = flow.NextFlowInDoc;
    }
    
  • Where can I find the text to an empty TextFrame fillColor? [CS3]

    I have a Javascript that needs fillColor text in a TextFrame.

    You can set the fill color of text on an empty block and InDesign will use this value when you enter the text... but before enter you text, where can I get this value?

    Currently, for the empty linked text frames I use pageItem.appliedObjectStyle.appliedParagraphStyle to retrieve the other settings. However, the value "fillColor" always seems to be (0,0,0,100).

    Where I find this value?

    Thank you!

    Hello

    try to read from

    pageItem.parentStory

    Robin

    www.adobescripts.co.UK

  • find the text remove textFrame

    in the 'TEST' is written find blocks of text

    I want to delete textframe

    var myDoc = app.activeDocument;    
    var myFrame = myDoc.allPageItems;
    for(var i=0;i<myFrame.length;i++){
    if(myFrame[i] instanceof TextFrame){
    if(myFrame[i].indexOf("TEST")){
    myFrame.remove();
    }
    }
    

    Is that what you need?

    var myDoc = app.activeDocument;
    var myFrame = myDoc.allPageItems;
    for(var i=0;i 0)
                    {
                            myFrame[i].remove();
                        }
                }
        }
    
  • Find the text article by article

    Hi my friends, once again with a new question here.

    Looking for exponent, that I have no problem using xml tags or text selection, but no way to carry out this chapter by chapter.

    Here's a piece of the script I'm workin on... .it stops with the error on red line

    var mySec = app.activeDocument.sections.count ();

    Alert ("Sections in the document:" + mySec);

    for (s = 0; s < = mySec-1; s + +) {}

    var mySecItm = app.activeDocument.sections.item (s);

    Alert ('Pages in the section' + (s + 1) +":"+ mySecItm.length);

    app.findGrepPreferences = app.changeGrepPreferences = null;

    app.findGrepPreferences.position = Position.SUPERSCRIPT;

    app.findGrepPreferences.findWhat = '. '. + » ;

    apici var is app.activeDocument.sections.item (s) .findGrep ();.

    Alert ('Section' + (s + 1) +"contains"+ apici.length + "Exhibitor");

    }

    Any ideas will be appreciated

    Thank you

    Hello

    a gap, page or a section may not be a target to find. Grep() method.

    It can be treated with app, doc, level objects lower story, textFrame, table and so on.

    I suggest you change this part:

    var apici = app.activeDocument.findGrep();
    var Res = [];
    var l = apici.length;
    while (l--)
         if (apici[l].parentTextFrames[0].parentPage.appliedSection == mySecItm)
              Res.push(apici[l]);
    

    so finally Res table should gather all found good texts

    Rgds

    Jarek

  • rather than anchor image by finding the text...

    Hi scripting gurus & everyone,

    We work with InDesign CS3 files. And we need to put two different icons as objects of anchoring in the margins by finding respective legends. If the legend is "[pair-icon]" means the icon P (i.e. the image), which should be placed as anchored object. If the legend is "[group-icon]" means the icon-G (i.e. the image) which must be placed as anchored object. The icons have about 3 pica height and width. He will always be just to the left of the margin in front and back pages. Of automation for investments of object anchor is new for us.

    Can someone help me with this.

    Thanks in advance.

    Indana

    Here's the complete script. Based on the fact that your library is open, that it contains two assets that have been appointed, and that you have an object named "icon" style You can also set the search options (include notes, stories, locked, etc..)

    The script for this: find all instances of [P-ICON] and [G-ICON] (which is [[PG] - ICON] in GREP). Browse the table of found items (findGrep (true) returns the items in reverse order), inserting an asset to the last point of insertion of each instance found. Each instance concluded (i.e. each myFound [i] .silence) is the name of an asset.

    This marginal stuff is good fun. I just put to evil together a system of information on the dynamic margin (http://www.kahrel.plus.com/indesign/sidenotes.html).

    Peter

    #target indesign
    
    myDoc = app.documents[0];
    myObjectStyle = myDoc.objectStyles.item ("icon");
    myLib = app.libraries[0];
    
    app.findGrepPreferences = null;
    app.findGrepPreferences.findWhat = "\\[[PG]-ICON\\]";
    var myFound = myDoc.findGrep (true);
    try
       {
       for (i = 0; i < myFound.length; i++)
          {
          myIcon = myLib.assets.item (myFound[i].contents).placeAsset (myFound[i].insertionPoints[-1])[0];
          myIcon.appliedObjectStyle = myObjectStyle;
          myFound[i].remove ();
          }
       }
    catch (e) {alert (e.message)}
    
  • Find the text box has disappeared

    The strangest thing happened, the box "search text" (you know, which appears when you press Ctrl + F) simply disappeared, I press Ctrl + F and search, but the box is not there, so it is difficult to move forward, and I can not go back at all. Please help - it is really essential.

    Thank you!

    It is possible that the screen is too high and the scroll bar and the search bar and the bar of the add-on to fall down.

    Open the system menu via Alt + space and see if you can resize the window.

    If it works then close Firefox (file > exit/Quit) to save the setting.

    See also:

    If the above didn't help then see:

    Start Firefox in Firefox to solve the issues in Safe Mode to check if one of the extensions of the origin of the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > appearance/themes).

  • I can't find the text file when a new right click

    Hello

    1. I can't text fint file when I click right click...  new (menu).

    We show other programs but no text file.

    2. in the same menu, how can I organize other applications ' If I want to remove one or other put on ?

    Thank you

    http://www.Vistax64.com/tutorials/154554-new-context-menu-restore-default-menu-items.html

    How to restore missing default new items of the context Menu in Vista

    http://www.Vistax64.com/tutorials/112102-new-menu-context-file.html

    How to add and remove an item from the new Menu in Vista

    See you soon.

    Mick Murphy - Microsoft partner

  • Get the text of a button when it is read as a node. VBox loop

    I learn JavaFX, and it's just a small matter of programming.

    I have 3 buttons in a VBox. And I want to apply the same 3 effects on all of the buttons after I put them in the Vbox. But when I use a loop and getChildren() on the VBox, they are returned as "nodes". I can't use Button.getText () to find the text of the button.

    Is there a way I can getText to a node? Or maybe convert the current node to a button and get the text in this way?

    VBox, vbox = new VBox();

    Option 1 button = new Button ("first button");

    Option 2 button = new Button ("Second button");
    Option3 button = new Button ("display rules");

    vbox.getChildren () .add (option1);
    vbox.getChildren () .add (option2);
    vbox.getChildren () .add (option3);

    for (button end node: vbox.getChildren ())
    {
    button.setOnMouseEntered (new EventHandler < MouseEvent >)
    {
    @Override
    public void handle (MouseEvent arg0)
    {
    button.setEffect (addEffect (Color.web("#53CFA6"),.8, 10));
    }
    });
    button.setOnMouseExited (new EventHandler < MouseEvent >)
    {
    @Override
    public void handle (MouseEvent arg0)
    {
    button.setEffect (addEffect (Color.web ("#FF6800"),.8, 10));
    }
    });

    button.setOnMouseClicked (new EventHandler < MouseEvent >)
    {
    @Override
    public void handle (MouseEvent arg0)
    {
    button.setEffect (addEffect (Color.web ("#E62800"),.8, 10));

    To do button.getText)
    Button; button.getText (work)


    }
    });
    }

    Hello user,.

    You must have formatted your code correctly. See the forum guides for formatting codes.

    To get the instance of the button, you need to do it safely
    There are two ways to get the instance of the Button.

    for (final Node button : vbox.getChildren()){
         Button b = null;
         if(button instanceof Button){
              b = button;
         }
    
         if(b != null){
              //Do your stuffs here
         }
    }
    

    Or you can even do like that too

    for (final Node button : vbox.getChildren()){
    
         Button b =null;
         try{
              b = (Button) button; //casting the class
         }
         catch(ClassCastException e){
              e.printStackTrace();
         }
    
         if(b != null){
              //Do your stuffs here
         }
    }
    

    Thank you
    Narayan

Maybe you are looking for