How to look for a particular phrase in a document???

Hey guys, I'm a little new at this thing... I need to figure out a way to make Java search through a document looking for instances of particular phrases, and replacing them with something else. For example, have it look for "A B C" and replace each such combination of words with "D E F". The search/replace needs to look for a few different phrases at once.

String.replaceAll is a fine answer, but you are creating Strings left, right & center, tis best to use a StringBuilder/Buffer.
    private static void replaceAll( StringBuilder sb, String search, String replace ) {
     int index = sb.indexOf( search, 0 );
     while( index >= 0 ) {
         sb.replace( index, index+search.length(), replace );
         index = sb.indexOf( search, index );
    }

Similar Messages

  • How to look for a particular field in the segments of IDOC ?

    Hi,
    I am looking at a particular IDOC which I will use to do data trasfer from lgacy to R/3 using BAPI in LSMW. Now I know a field which is required to create a given business transaction when igrating data. But there are 100's of segments on the IDOC.
    Is there a way I can see if the given field is present in any of the IDOC segment ? I don't want to dig though each and everys egment and find it out...
    Regards,
    Rajesh

    Try using WE09..There you have the option of searching by the idoc data..CHeck in the bottom of the selection screen
    Thanks,
    Naren
    Message was edited by: Narendran Muthukumaran

  • How to look for the Table Name

    Hi Friends,
    Sometimes we need to download the table for the desired information if the same is not available from a particular report. How to look for the table name? Is there a report or a particular feild, where we can find the name of the particular table?
    Thanks for the assistance.
    Regards

    Hi Friend,
    If you want to see the structures then go to SE11. Sometimes it happens that you cannot find the table names but only fields. In such case, if you want to find the Table names which is not available, then go to SE90.
    Abap Dictionary > Fields > Table Fields.
    Now Enter the Field name in Right Hand Side of the screen then Execute. You will see the all tables by which that Fields are used.
    Regards,
    Jigar

  • Looking for a particular email

    I have Mail backed up to TM as well as an external drive. I am looking for a particular email that has been backed up. I moved the particular mailbox from each of these drives to my desktop. They are .imapmbox files and would like to import these messages into Mail as a separate disposable folder.
    On the desktop they are #.emix files which are not easy to search.
    How to do this?
    Thanks

    I'm not sure. I know you can import mail stored locally by opening Mail and selecting Import from the File menu. Select the Apple Mail option then follow directions. A file Open dialog will appear and you must navigate to the /Users/username/Library/Mail/ folder and select the Mailboxes folder. If your mail is there then you can select the mailbox and import it. However, this does not work for IMAP accounts. Make a copy of the .mbox file that should have your mail. Again select Import from Mail's File menu. Select the bottom option to import .mbox mail and follow directions.
    Imported mail will appear in a separate sidebar header called Imported Mail.

  • Scan\Look for a particular character in a file

    I would like to look for a particular character(@) in a file. The character might be in a word. When if find the character I want to read the actual whole word that contains that character.
    What's the best way of going abt this?
    Thx,
    Kapapra.

    Read the file line by line using BufferedReader.
    Tokenize each line on space.
    Loop through the token strings.
    For each token that contains the character that you are looking for (e.g. @) found using indexOf operator of the String class, print or save (or whatever you want to do with that token) that token.
    Continue reading the file line by line till the end of the file.
    Does this make sense? Look the java.io package API for the details on how to read the file and stuff.
    If anyone has more effecient method to do this, please share.

  • How to look for spaces in an extract file in order to trigger a MOVE_IT rule

    In studio I am defining a variable field on a section and I want to pull information from my extract file using a simple MOVE_IT rule. 
    I am trying to pull information from a record that has spaces in columns 10-14.  How do I enter the information required in the DATA field to request this? 
    For example, if I was pulling the information from a record that had "XXXXX" in column 10-14 I know the DATA field would be 10,XXXXX
    I cant seem to figure out how to look for spaces at a particular offset.
    Thanks.

    Using XPath to locate the elements you are after is very easy.
    Try something like this:
    import java.io.File;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.transform.Transformer;
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.dom.DOMSource;
    import javax.xml.transform.stream.StreamResult;
    import javax.xml.xpath.XPath;
    import javax.xml.xpath.XPathConstants;
    import javax.xml.xpath.XPathFactory;
    import org.w3c.dom.Document;
    import org.w3c.dom.NodeList;
    import org.xml.sax.InputSource;
    public class BasicXMLReplaceWithDOM4J {
         static String inputFile = "C:/student.xml";
         static String outputFile = "C:/studentRenamed.xml";
         public static void main(String[] args) throws Exception {
              // Read xml and build a DOM document
              Document doc = DocumentBuilderFactory.newInstance()
                        .newDocumentBuilder().parse(new InputSource(inputFile));
              // Use XPath to find all nodes where student is named 'Suresh'
              XPath xpath = XPathFactory.newInstance().newXPath();
              NodeList nodes = (NodeList)xpath
                   .evaluate("//stud_name[text()='Suresh']", doc, XPathConstants.NODESET);
              // Rename these nodes
              for (int idx = 0; idx < nodes.getLength(); idx++) {
                   nodes.item(idx).setTextContent("Suresh-Renamed");
              // Write the DOM document to the file
              Transformer xformer = TransformerFactory.newInstance().newTransformer();
              xformer.transform(new DOMSource(doc), new StreamResult(new File(outputFile)));
    }- Roy

  • How  to  look for  fi doc  number in cj88

    HI  expert:
          when I  run cj88.   the system generate FI  doc number.   how to look for FI doc number.
    can you tell me !
    thank you !!!!

    Hi,
    You can see the FI Doc. thru' given instruction
    Go to T-code CJI3 then fillup the WBS no. in which you want to see the Settlement document.
    Execute then filter up document type AA  double click on this & click on FI document.
    Hope it will solve your problem.
    Regards,
    Vishal Kr. Sharma

  • How to look for kMAT material in Testing client?

    Hi PP members:
    How to look for KMAT material in Test client,
    Note: I went to mm60 and entered material type: KMAT it did not populate any
    materials
    Is there any way where I can find the materials, If yes please let me know
    thanks
    Suren

    Hi Saritha:
    When I went to SE16, and entered MTART as KMAT it giving the following
    It is replying me back "No table entries found for specified key"
    Also want to bring to your kind attention I left MATNR field blank as I donot know
    the VC materials
    thanks

  • How to look for business partner number in GTS

    Hi Experts,
    How to look for the business partner number in GTS when we have the Customer Id number in r/3?
    Please let me know the path in GTS.
    Edited by: Anurag87 on Dec 9, 2010 2:17 PM

    Hello,
    just simple in GTS in transaction BP find by "3 External number" (which is yours R/3 number).
    Or in se16 table /SAPSLL/PNTBP type in field BPVSY you external number from R/3 system.
    Cheers,
    Gabriel.

  • How to look for a keyword in SAP MaxDB Library 7.6

    Hi,
    how to look for a keyword in SAP MaxDB Library 7.6 ( http://maxdb.sap.com/doc/7_6/7e/c3fb0e72fcf84580f7ee9fcec672b7/frameset.htm)
    Thank you.

    http://maxdb.sap.com/documentation/
    =>
    Section u201CDownloadu201D - HTMLHelp file < 7.8 or 7.7 version >
    HTMLHelp file
    .chm, full text search, print-optimized, 6.3 MB
    < download it or open it >
    < If downloaded, Then start on your server:
           maxdb-chmdoc-en-78_740.chm   >
    and type a keyword in field u201CType in the keyword find:u201D and search.
    Itu2019s working fine.
    Regards, Natalia Khlopina

  • How to look for sales order number if I know outbound delivery number?

    How to look for sales order number if I know outbound delivery number?

    Hi ,
        If you want to see the Sales order Number from Outbound delivery or invoice,go to their respective T-codes,say for example,
    for delivery,Goto Tcode: VL02N / VL03N.There you will find Document Flow Icon,click on that,or press F7.
    You will get a window,there you can see the Sales order Number before your outbound delivery Number
    With Thanks and Regards,
    Priya

  • Looking for a particular vlaue in a id array

    i have a program which generates me 1000000 sample values ie a array of 1 million values.in this 0ne million values i need to look for a particular range of values ie allthe values in the array are 4 and then they ia a value like say 10 and some more values. i need to detect the values greeater than four and then take the 20 values from the index where it is detected. i may have hundered of this pattern in the million samples.

    I am attaching a VI which does what you want. The diagram is pretty straight-forward. Let me know if you don't understand anything.
    Regards,
    Khalid
    Attachments:
    chkarray.vi ‏34 KB

  • How to search for a particular word in a string?

    How to search for a particular word in a string?
    thanks for your help....

    This works fine.
    public class Foo {
        public static void main(String[] args) {
        String s = "Now is the time for all good...";
        String s2 = "the time";
        System.out.println(s.contains(s2));
        System.out.println(s.contains("for al"));
        System.out.println(s.contains("not here"));
    }output:true
    true
    falseYou must have something else wrong in your code.
    JJ

  • How to search for a particular word in a long document?

    How to search for a particular word in a long document?

    What program are you using to read the document?
    Good luck.

  • How to search for a particular pattern in a string

    Hi,

    Hi ,
    How to search for a particular pattern in a string?
    I heard about java.util.regex; and used it in my jsp program.
    Program I used:
    <% page import="java.util.regex"%>
    <% boolean b=Pattern.matches("hello world","hello");
    out.println(b);%>
    I run this program using netbeans and am getting the following error message.
    "Cannot find the symbol : class regex"
    "Cannot find the symbol : variable Pattern "
    How to correct the error?

Maybe you are looking for

  • Password for JPICERTS

    I would like to be able to use the Java Plug-in Console to import an object signing certificate (PKCS #12 format) into the Signed Applet certificate store (jpicerts). I would then like to use jarsigner with that certificate. I have no problem with th

  • How do I view a FUNCTION within a Package Body

    I can see the FUNCTION being executed within the Package... FUNCTION Stop_Refresh_AsBilled RETURN Number; And within Oracle SQL Developer and using the Connection and "Packages" part of the Schema, I see the Function Name. However, when I <Double-Cli

  • Project performamce

    ihave created a project and generate draft invoice and interface to AR . How ever i am not able to see the billed amount in Billing and Collection region in Perofrmace tab (Under Reporting) Can any one please tell me which step i am missing ??

  • Activex Error.

    Hi, we installed FR Studio on a new system and facing some errors. This is a FR 11.1.1.3 version on a clients desktop. The error is "Runtime error"429". Activex cant create an object". Please suggest what would be the error. Thanks,

  • URLConnection with large amount of data causes OutOfMemoryError: Java heap

    I am setting up a system where my customers can sent me their data files to my server. If I use a simple socket with a server permanently running on a chosen port, my customers are able to transfer files of any size without problem. However, If I ado