Searching for a string in given text file

Hi,
I have two strings and i need to search the entire file for the strings and highlight the lines between the strings
say, for example,
hi this is xyz
i am a begineer in java
can i have some help in this issue please
i gave 'hi' and 'can' i need the three lines to be highlighted
can you give me an idea about this.
how to proceed
thanks all in advance
Edited by: anub on Feb 6, 2009 3:24 AM

Here's an idea. Find a link to the java API. Create a utility class with a method to read a file and a method to write a file. Look in java.io for this. That should keep you busy for a while and give you something specific to ask questions about. Next, create a GUI class and put a button on it. Figure out how to make a button click open a "FileChooser" or "JFileChooser" (Look in the api for that) Imagine that these need to talk to each other so figure out what parameters are needed. After you've done that then figure out how the user is going to enter the two search criteria (something that acts like a text field). Choose a GUI class that supports text highlighting. Display all the information that the user would like to know e.g. The name of the file selected to parse, the name of the file to write, and whether the strings were found successfully.
kr
walker

Similar Messages

  • How do i search for a string in a txt file using java??

    How do i search for a string in a txt file using java??
    could you please help thanks
    J

    Regular expressinos work just fine, especially when
    searching for patterns. But they seem to be impying
    it's a specific group of characters they're looking
    for, and indexOf() is much faster than a regex.If he's reading from a file, the I/O time will likely swamp any performance hit that regex introduces. I think contains() (or indexOf() if he's not on 5.0 yet) is preferable to regex just because it's simpler. (And in the case of contains(), the name makes for a very clear, direct mapping between your intent and the code that realizes it.)

  • Searching for a string in an excel file and return true if found.

    How can I search for a string in an excel file and return true if found, its location and also a value.

    The problem with searching an excel file is that it contains a header. It would be easiest if you just read the file into a LabVIEW array and search the array. This way you can also get the index and the value of the location.

  • Search for a character in a text file

    I have a text file generated using utl_file. After this is generated, I want to search for a specific character in the file. If found, I want to edit the file and remove/replace this character.
    Any ideas are appreciated.
    Thanks

    If your application resides on unix box, you can use OS command to find and replace, something like "sed" in unix, do a man on sed and find out the details.

  • How do I search for a string in the Text tab of the Layers panel

    I have a world map with a text layer for country names.  I hide the country names as needed by clicking on the 'eye' icon for Toggle Visibility in the Layers panel.  I've inadvertently hidden one name and I need to know how to find it in the Text panel so I can make it visible again.  How do I seatrch for a name in the Text panel?

    Just in case there is an unlocked and visible object close to the hidden one in the stacking order, you may select that object right on the artboard and then go to the Layers palette menu and take the Locate Object command.
    Of course, this would be just one possible workaround to locate the hidden objects a bit easier.

  • How to search for perticular substring in given string.

    Hi, Can any one tell me how to search for perticular substring in given string.
    example:
    I have to search for CA in given Order type it may be CA10 or CA15. Please Do the needful.

    Hi Aniruddha,
    check this...
    Data var string,
    var = 'India'.
    search var for 'Ind'.
    if sy-subrc = 0.    " var having ind
    Message 'Ind found' type 'I'.
    else  .            "var not having ind
    Message 'Ind not Found' type 'I'.
    endif.
    thanx
    bgan.

  • Search for a String in a list of files

    Could anyone please send me a java sample code which searches for a string from a list of files and returns me the filename and the line in which the Search String was found ?
    Thanks in advance
    RR

    Simple solution would be -
    1. Traverse a directory for each file.
    2. Read each file using Buffered Reader.
    3. Use readLine() method to read a line.
    4. Use String.indexOf to see if the data which you are looking for is there in the line or not.
    5. If its there then store the line number and file name.
    6. When the loop will end you will have list of file name and line number where the data which you are looking for is present.

  • Reading Each String From a text File

    Hello everyone...,
    I've a doubt in File...cos am not aware of File.....Could anyone
    plz tell me how do i read each String from a text file and store those Strings in each File...For example if a file contains "Java Tchnology forums, File handling in Java"...
    The output should be like this... Each file should contains each String....i.e..., Java-File1,Technology-File2...and so on....Plz anyone help me

    The Java� Tutorials > Essential Classes: Basic I/O

  • How can I search for a string like a partial IP address in the global search

    When searching for a string like "10.255." the global search finds messages containing "255" or "10" and both.
    This happens no matter whether quotation is used or not.
    When quotation is used it probably will match on the given order as well, but beeing in the timezone '+0100' the string "10" is always found first (in the email headers...).
    Is there a way to tell the global search not to use '.' or any other character as whitespace?

    When searching for a string like "10.255." the global search finds messages containing "255" or "10" and both.
    This happens no matter whether quotation is used or not.
    When quotation is used it probably will match on the given order as well, but beeing in the timezone '+0100' the string "10" is always found first (in the email headers...).
    Is there a way to tell the global search not to use '.' or any other character as whitespace?

  • Writing a string into a text file

    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.PrintStream;
    public class Main {
    public static void main(String[] args) {
    String result;
    result = "testtest";
    try {
    PrintStream ps = new PrintStream(new FileOutputStream("D:\\test\\output.txt"));
    ps.println(result);
    ps.close();
    } catch (Exception e) {
    System.out.println(e);
    I have a couple of string to write into text file
    ---- for example--
    String test1="aaa";
    String test2="bbbb";
    String test3="c";
    String test4="dd";
    --- condition to write into text file....
    test1 has to write between 1 - 5 position.
    test2 has to write between 6 - 15 postition.
    test3 has to write between 16 - 10 position.
    test4 has to write between 11 - 15 position.
    how can i write those strings into a certain position?
    how can i write those strings for 3 times in a text file?(make 3 rows)

    figure out how write them into a string, then use my helper util class like this:
    String str = "some\nstuff\nhere";
    ASCIIFile file = new ASCIIFile("c:/somefile.txt");
    file.setContents(str);
    //done, file written!code for ASCIIFile can be found here:
    http://www.doesthatevencompile.com/current-projects/code-sniplets/ASCIIFile.htm
    change its package to work with your codes

  • Search for a String within a document (Word, txt, doc) using JSP, JAVA

    Hi
    I have created a little application that uses combination of JSP and HTML. Users of this application can upload documents which are then stored on the server. I need to develop functionality where I can allows users to search for a string within a document. More precisely, user would type in some string in a text box and application will search all uploaded documents for that string and return the downloadable links to those documents that contains that string. I have never done this before. I was wondering if someone could get me started on this or point me to some thread where this idea is already discussed. Any Jave code exists for searching through documents??
    Thanks for your help
    Riz

    http://www.ibm.com/developerworks/java/library/j-text-searching.html
    http://en.wikipedia.org/wiki/Full_text_search
    Type these parameter in yahoo:+efficient text search
    you will need something like openoffice library to read microsoft word document.

  • Search for a string in SAP Script

    Hello Experts,
    Is there a way to search for a string in all Z SAP scripts, like ABAP source scan?
    Regards,
    Hari.

    Try using function module "READ_FORM" (you will have to write a simple z-program to find all SAPscripts in your system then use this function module to search the SAPScript Forms for a particular string).
    All you have to do is supply the "FORM" name and it will return all of the Pages, Paragraphs, and Texts etc....
    More specifically, try looping at the "FORM_LINES" internal table result and you will see the SAPScript text there....
    Have fun    !
    Edited by: Christopher Twirbutt on Sep 16, 2009 12:43 AM

  • Search for a space within a text field

    Hi All
    I am trying to search for a sapce within a text field but sofar not being very successful. I have used:
    FIND search_str
               IN text_str
               MATCH COUNT  lv_mcnt
               MATCH OFFSET lv_moff.
    where search_str = TYPE c VALUE ' '.
    I am looking a way of searching a character within the string using ABAP (like INSTRING in other languages). If you have similiar codes - Could you please post me a copy - Thanks

    HI
    Check this..
    DATA string7(30) TYPE c VALUE 'This is a little sentence.'.
    WRITE: / 'Searched', 'SY-SUBRC', 'SY-FDPOS'.
    ULINE /1(26).
    SEARCH string7 FOR 'X'.
    WRITE: / 'X', sy-subrc UNDER 'SY-SUBRC',
                   sy-fdpos UNDER 'SY-FDPOS'.
    SEARCH string7 FOR 'itt   '.
    WRITE: / 'itt   ', sy-subrc UNDER 'SY-SUBRC',
                       sy-fdpos UNDER 'SY-FDPOS'.
    SEARCH string7 FOR '.e .'.
    WRITE: / '.e .', sy-subrc UNDER 'SY-SUBRC',
                      sy-fdpos UNDER 'SY-FDPOS'.
    SEARCH string7 FOR '*e'.
    WRITE: / '*e ', sy-subrc UNDER 'SY-SUBRC',
                    sy-fdpos UNDER 'SY-FDPOS'.
    SEARCH string7 FOR 's*'.
    WRITE: / 's* ', sy-subrc UNDER 'SY-SUBRC',
                    sy-fdpos UNDER 'SY-FDPOS'.
    Thanks ,
    Praveen

  • How to write Strings in a text file with BufferedWriter

    I've got a Vector object full of Strings objects, I'm interested in wrinting these Strings in a text file with a BufferedWriter , I would apreciate some code, thank you

    http://java.sun.com/products/jdk/1.2/docs/api/java/io/BufferedWriter.html
    "PrintWriter out = new PrintWriter(new BufferedWriter((new FileWriter("foo.out")));"

  • How to search for a string in ALL Function Modules source code

    Hello,
    I want to search for the string "HELLO" in all FUNCTION MODULES source code(FM, no reports/programs).
    Is this possible? How?
    Cheers,
    Andy

    hi,
    Execute RPR_ABAP_SOURCE_SCAN to search for a string in the code ... Press where-used-list button on the program which takes to the function group or the function module where it is used ..
    Regards,
    Santosh

Maybe you are looking for

  • Syncing iPod touch is like playing in the lottery

    When I sync my iPod touch 4G, it'll begin its normal sync method of backing up, syncing contacts, ect... But more recently, it has been stumbling on backing up(which more or less I'll refer to as "syncing" for simplification here). It'll take about 5

  • Application Object in a JSP page

              Hi,           I want to maintain a persistent object which stores the customised settings of           each user coming to my site. I cannot do that in cookie because the settings are           alot and moreover it is confidential too. So i

  • Oracledbconsoleorcl service is not running ?

    i installed oracle database and developer suite 10g and the service mentioned was working properly at the first time , but when i restarted the computer it did not work , and when i try to start it , this message appears windows couldn't start the or

  • Purchase Orders without prices

    Hi,   I' m creating Purchase orders using code, this is ok, but, when check in the puchase orders forms and find the document, the column price is not setting and in the DB (table POR1) the price column is setting. The code is: SAPbobsCOM.Documents  

  • Regd FIle Event Generator

    Hi, Am having a file event generator,and the presence one such file[string type] in the folder would trigger one of my JPD's. Now, I want to read the contents of the file as well, in addition to the complete file name..I guess this can be done by rea