Searching Sub String

Any idea how can I search a sub string from a String ignoring white spaces.
Ok, I need to Search a sub string ("for update") from a given String (henceforth Source String) but the condition is it might contain any number of white spaces between these two words (in source string).
So how can I search for "for update" in Source String ignoring any number of (but at least one) white spaces it might have in the source string.
(One way can be searching index of "for" than checking value at index+2 for "update"...and keep trying until i search through entire length of String...but I need some optimized way to do it as I need to check this virtually infinite times in my application)

you should "normalize" the string you are searching - that is - first scan it for white space and replace them with single spaces. Then convert it to lower case and search it for what you wish. You could use StringTokenizer -
StringTokenizer st = new StringTokenizer( toBeSearched, " \r\n\t" );
StringBuffer sb = new StringBuffer();
while( st.hasMoreTokens() ) sb.append( st.nextToken() + " " );
String toBeSearchedN = sb.toString().toUpperCase().toLowerCase();
String toSearchForN = toSearchFor.toUpperCase().toLowerCase();
boolean result = ( toBeSearchedN.indexOf( toSearchForN ) != -1 );

Similar Messages

  • Regarding sub string

    Hi i am geting an out put like this from given text "336 341 sunil" here can i get i prefix and post fix to the this string and highlight it.is this possible.can i use sub strings here
    vijay

    hi
    here this code is help full in getting the reslt what i am looking for....
    ie to get the searched result as hyper link
    selString=document.substring(annot.getBegin(),annot.getEnd());
         String preStr= "", postStr="";
         if(annot.getBegin()-20<0)
              preStr = document.substring(0,annot.getBegin());
         else
              preStr = document.substring(annot.getBegin()-20,annot.getBegin());
         if(annot.getEnd()+20>document.length())
              postStr = document.substring(annot.getEnd(),document.length());
         else
              postStr = document.substring(annot.getEnd(),annot.getEnd()+20);
         String outputStr =preStr+"<label style='background-color:yellow;'>"+selString+"</label>"+postStr;
         if(i==0){
              StrTemp=document.substring(0, annot.getBegin())+selString;
         }else{
              StrTemp=StrTemp+document.substring(intTemp, annot.getBegin())+selString;
         intTemp=annot.getEnd();
         out.println(outputStr+"<br><a href='OutputServlet?file="+aFile.getAbsolutePath()+"&begin="+annot.getBegin()+"&end="+annot.getEnd()+"'>"+aFile.getName()+"</a><br><br>");
         /* TestType annot = (TestType)itr.next();
         out.println("Test UIMA Servlet Begin::"+annot.getBegin()+"<br>");
         out.println("Test UIMA Servlet End::"+annot.getEnd()+"<br>");
         out.println("Test UIMA Servlet Content::"+annot.getCoveredText()+"<br>");
         out.println("Test UIMA Servlet End::"+annot.getType()+"<br>"); */
         i++;
    StrTemp=StrTemp+document.substring(intTemp,document.length());
    thnak u for ur replies

  • Help required- Searching Particular string in column

    Hi,
    I have a table by name temp and 2 values in the table. I'm using LIKE caluse to search a string. I'm getting output for some particular string. Please correct the below query for me.
    I have given a table/data reference for you:
    Create table temp(col1 varchar2(255));
    insert into temp values ('Test_Scale_High');
    1 row inserted
    insert into temp values ('Test_Scale_High');
    1 row inserted
    commit;
    select * from temp;
    col1
    Test_Scale_High
    Test_Scale High
    select * from temp where upper(col1) like '%TEST_SCALE%';
    COL1
    Test_Scale_High
    Test_Scale High
    select * from temp WHERE UPPER(COL1) LIKE '%TEST_SCALE_%';
    COL1
    Test_Scale_High
    Test_Scale High
    select * from temp WHERE UPPER(COL1) LIKE '%TEST_SCALE_H%';
    No Row Selected
    Thanks,
    Santhosh.S

    santhosh.shivaram wrote:
    select * from temp;
    col1
    Test_Scale_High
    Test_Scale High
    select * from temp where upper(col1) like '%TEST_SCALE%';
    COL1
    Test_Scale_High
    Test_Scale High
    select * from temp WHERE UPPER(COL1) LIKE '%TEST_SCALE_%';
    COL1
    Test_Scale_High
    Test_Scale High
    If I understand your requirement correctly you need to escape the Wild Card '_'
    Hope the following code helps:
    SQL> set feedback on;
    SQL> SELECT * FROM TEMP
      2  /
    COL1
    Test_Scale_High
    Test_Scale High
    2 rows selected.
    SQL> SELECT *
      2    FROM temp
      3   WHERE UPPER (col1) LIKE '%TEST_SCALE%'
      4  /
    COL1
    Test_Scale_High
    Test_Scale High
    2 rows selected.
    SQL> SELECT *
      2    FROM temp
      3   WHERE UPPER (col1) LIKE '%TEST_SCALE\_%' ESCAPE '\'
      4  /
    COL1
    Test_Scale_High
    1 row selected.
    SQL> SELECT *
      2    FROM temp
      3   WHERE UPPER (col1) LIKE '%TEST_SCALE_H%'
      4  /
    COL1
    Test_Scale_High
    Test_Scale High
    2 rows selected.
    SQL> SELECT *
      2    FROM temp
      3   WHERE UPPER (col1) LIKE '%TEST_SCALE\_H%' ESCAPE '\'
      4  /
    COL1
    Test_Scale_High
    1 row selected.
    SQL>Regards,
    Jo
    Edited by: Joice John : Added 2 Sample Codes

  • How to extract sub string value from a string?

    Hi,
    I need to know how can i extract sub strings from a main
    string, something like this:
    main variable-------->"2087-5E2SE-19-JG7BC"
    i want to split it into like this:
    sub_main_1 variable---------> "2087"
    sub_main_2 variable---------> "5E2SE"
    sub_main_2 variable---------> "19"
    sub_main_2 variable---------> "JG7BC"
    I did the same in flash by using Split and arrays, like this:
    var my_str:String = "2087-5E2SE-19-JG7BC";
    var my_array:Array = my_str.split("-");
    for (var i = 0; i<my_array.length; i++) {
    trace(my_array
    this.aaa1 = my_array[1];
    this.aaa2 = my_array[2];
    this.aaa3 = my_array[3];
    this.aaa4 = my_array[4];
    My question is that how can i do the same in director ?? i
    haven't find any split function in director.
    Thanks in advance,
    Amir

    You do a similar thing in Director using the itemDelimiter,
    which is a
    _player object property in MX2004. By default, it's a comma:
    put _player.itemDelimiter
    It will let you get specific items within a string.
    p = "2087-5E2SE-19-JG7BC"
    _player.itemDelimiter = "-"
    put p.item[1]
    -- "2087"
    You could use it to write yourself a little split function:
    on split(theString, theDelimiter)
    oldDelim = _player.itemDelimiter
    _player.itemDelimiter = theDelimiter
    itemList = []
    repeat with cnt = 1 to theString.item.count
    itemList.add(theString.item[cnt])
    end repeat
    return itemList
    end
    p = "2087-5E2SE-19-JG7BC"
    a = split(p, "-")
    put a
    -- ["2087", "5E2SE", "19", "JG7BC"]
    Dave -
    Adobe Community Expert
    www.blurredistinction.com
    http://www.adobe.com/communities/experts/

  • How to search a string in some folder.

    Hi ,
    In my application users will upload some pdf,xls files to server. files will be saved in server. From the front end can search on all files with some specific string. If that string is there in any of the file, user has to get link to download that file and the text just before and after that user string. Its like how we get in google. This type of search we need to implement, Could any one please let me know how to implement, any free API are there in java. Please its urgent, help on this.
    Thanks
    Mohan

    user594301 wrote:
    I have 2 columns in a table. entry_no and msg_txt. entry_no is number(12) and msg_txt is LONG. I want to search one string in msg_txt. How can I write a query for this ?You can't write a query for this. The only thinks you can do with a long in a query is put something in and take it out again - with diffiuclty, usually.
    You can write a PL/SQL function to do this for you if necessary. The function will have to perform the search directly if the long < 32760 bytes or use DBMS_SQL to break the LONG up into 32760 byte segments that can then be manually searched. If you are lucky someone has done this already and posted the code online. Either way the solution will be slow and probably painful to implement.
    If possible convert your data to a CLOB and use DBMS_CLOB to find the data you need.

  • Search a string with in some file and get the name of file

    i want to search a string in some files that are in a given directory and return the name of file having searched string.I am doing this with grep command as given below
    import java.io.*;
    public class linux_java {
    public static void main(String[] args) {
    try {
    String command = "find . | xargs grep -l Resolv /data2/opt/jakarta-tomcat-4.1.24/webapps/Oa/BOG/*.txt";
    final Process process = Runtime.getRuntime().exec(command);
    OutputStream os= process.getOutputStream();
    System.out.println("out put stream= " +os);
    PrintStream stdIn = new PrintStream(new BufferedOutputStream(process.getOutputStream()), true);
    System.out.println("Return code = " + stdIn);
    } catch (Exception e) {
    e.printStackTrace();
    i dont know how to get the name of file that are return by the execution of command through process object. Please send the code for the same

    thanks for your suggestion....
    i change the code but now it is giving error as /usr/bin/find incomplete syntax....but i am giving the right syntax....
    please confirm whether the syntax is correct...
    import java.io.*;
    import java.util.*;
    public class linux_java {
    public static void main(String[] args) {
    try {
    //String command = "ls -alt";
    String command = "find /data2/opt/jakarta-tomcat-4.1.24/webapps/Oa/BOG -type f -exec grep -sl 'Aggarwal' {} \\; 2>/dev/null";
    ///grep -l System test/*java
    System.out.println(" the command is"+command);
    final Process process = Runtime.getRuntime().exec(command);
    InputStream is = process.getErrorStream();
    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader br = new BufferedReader(isr);
    String line="";
    System.out.println(" the BufferedReader is"+br.readLine());
    while ((line = br.readLine()) != null) {
    System.out.println(" the files are"+line);
    } catch (Exception e) {
    e.printStackTrace();
    }

  • How to search a string from the database?

    how to search a string from the database? starting with some character

    If you're trying to do this in a SELECT, you can use the LIKE verb in your WHERE clause.
    Here's an Example
      SELECT obj_name FROM tadir
        INTO prog
        WHERE pgmid = 'R3TR'
          AND object = 'PROG'
          AND obj_name LIKE 'Z%'.
    In this case it will select every row that obj_name starts with Z. 
    If you wanted to find every row that the field obj_name contains say... 'WIN'  you use LIKE '%WIN%'.
    Edited by: Paul Chapman on Apr 22, 2008 12:32 PM

  • Increasing the speed of searching a string in a file

    I have to search a String in a big ASCII-file and have to delete it. Now I wrote a program which opens the source file and a target file. I am reading each line from the source file, check it and write it into the target file. It is working fine but it is very slowly.
    I check each line with:
    if (line.equalsIgnoreCase("xxxxx")) { }
    How can I make it much faster.
    Thank you for your help!
    Arthur

    IO is an issue, but I've noticed that changing the case of strings is very slow, probably because in unicode is harder than in ASCII.
    If you could replace the equalsIgnoreCase method by one or more equals, you'll get benefits. If you can, I would try something like the following to minimize the equalsIgnoreCase invocations:
    // Supose you are looking for "abcd"
    if (line.charAt(0) == 'a' || line.charAt(0) == 'A') {
       if (line.equals("xxxxx")) { }
    }Try it and let us know if it worth the effort.

  • Is it possible to search for strings containing spaces and special characters?

    In our RoboHelp project, there are figures with text labels such as Figure 1, Figure 3-2, etc.
    When I search for "Figure 3" I get all pages containing "Figure" and "3", even if I surround it in quotes.  Similarly, searching for "3-2" treats the '-' character as a space and searches for all pages containing '3' or '2'.
    Is there a way to search for strings containing spaces and special characters?

    In that case I think the answer is no if you are using the standard search engine. However I believe that Zoom Search does allow this type of searching. Check out this link for further information.
    http://www.grainge.org/pages/authoring/zoomsearch/zoomsearch.htm
      The RoboColum(n)
      @robocolumn
      Colum McAndrew

  • Rest query with filter sub-string (contains, not eq)

    Hi,
    how can I do a REST-query with a filter for a string-column which is only a sub-string? I only found EQ, for example $filter=(name EQ 'tom') which compares the whole string.
    But I would like to query records, where a string-column CONTAINS a specific sub-string.
    Thx, Tom

    Hi Tom,
    Do you use it on azure Data Market place? Did you try to add "*" on your query string, like this
    post.
    Also, you could try this tool from this
    thread. Also, for this issue, I suggest you could post it on
    SQL forum for better support.
    If I misunderstood, please let me know.
    Regards,
    Will
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Searching a string in Forms V5.

    Hi all,
    My requirement is to search a string in a Form (Forms Version 5.0.6.8.0. However If I go to <Filie-Administration-Object list report), I am getting a ascii file. All the objects in the form are listed in the file. So, I do a 'Search' of my required String in the ascii file.
    However, in the <Ascii> file, I find that the program units are not converted to txt file. Only the program unit's name is present.
    Is there any other method, by which I can search my required string in the form(includding all program units, viz., triggers, program units)?
    Thanks in advance for ur help.
    null

    Maybe this will help you:
    We have FREE versions of FormDiff and FormGrep,the productivity tools for Oracle Developer, available for downloading now.
    There are NO FORMS to fill out, NO LIMIT on how long you can use them and best of all NO COST.
    Check out the latest FormDiff features and download your FREE VERSION now: http://www.aug10.com/products/FormDiff
    Using FormDiff, you can now document changes made to Forms and perform meaningful code reviews.
    Checkout the latest FormGrep features and download your FREE VERSION now: http://www.aug10.com/products/FormGrep
    Using FormGrep, you can 'Find and Replace PL/SQL code' across hundreds of FMBs at a time.
    Thank you for your time,
    Jesse Johnson - Managing Principal
    August Tenth Systems, Inc.
    PO Box 3682
    Boulder, CO 80307-3682 http://www.aug10.com/
    Helena

  • SPECIFYING THE NUMBER OF IDENTICAL CHARACTERS WHEN SEARCHING A STRING

    Hey everyone,
    The built-in function indexOf() searches for a character "." in the string "1.2.3." if the value == 1.
    It searches nothing if the value == 0 or 2 or any number greater than 2.
    var txt:String = "1.2.3.";
    var output:String = String(this);
    if (txt.indexOf(".") == 1)
    trace(output);     //[object MainTimeline]
    The must be a simple method for specifying the number of characters "." when searching the string "1.2.3.".
    For example if there is 2 characters "." in the string "1.2.", then run through a statement but if it does not contain 2 characters "." then do nothing.
    There is a built-in function called contains but it is mainly used in XML.
    indexOf() looks like unstable javascript codes, one of those framework that unixers hate.

    Why have an alternative when the built-in RegExp class does the job better than anything else?   Is it that you find them too hard to work with?  If you want a one line solution and prefer to use the older built-in methods you can do so by creating your own custom class to do what you want... searching a string character by character for the one you wish to isolate and counting them.
    In any case, you have a solution to counting the number of "." characters.
    "Many" people say what?  I doubt many people say anything like that at all.

  • Searching a String in Script

    Hi All,
    I need one help is there any provision to search for string in standard or customized scripts....for example to search a string in programs..through program RPR_ABAP_SOURCE_SCAN i can search in program...same way how can i search for a text in scripts ??
    Regards
    VEnk@

    Continue....
    FORMAT COLOR COL_NORMAL INTENSIFIED ON.
      STXL_ID-TDOBJECT = 'FORM'.
      STXL_ID-TDID = 'TXT'.
      SELECT * FROM STXL CLIENT SPECIFIED
              WHERE MANDT    = PA_MANDT
                AND RELID    EQ 'TX'
                AND TDOBJECT EQ 'FORM'
                AND TDID     EQ 'TXT'
                AND TDNAME   IN SO_NAME
                AND TDSPRAS  IN SO_SPRAS.
        MOVE-CORRESPONDING STXL TO I_STXL.
        APPEND I_STXL.
      ENDSELECT.
      SORT I_STXL.
      CLEAR HUIDIGE_TDSPRAS_TDNAME.
      CLEAR VORIGE_TDSPRAS_TDNAME.
      LOOP AT I_STXL.
        STXL_ID-TDNAME  = I_STXL-TDNAME.
        STXL_ID-TDSPRAS = I_STXL-TDSPRAS.
        STXL_ID-TDID    = I_STXL-TDID.
        CONCATENATE STXL_ID-TDSPRAS STXL_ID-TDNAME
                    INTO HUIDIGE_TDSPRAS_TDNAME.
        IF HUIDIGE_TDSPRAS_TDNAME <> VORIGE_TDSPRAS_TDNAME.
          CONCATENATE STXL_ID-TDSPRAS STXL_ID-TDNAME
                                      INTO VORIGE_TDSPRAS_TDNAME.
          REFRESH LINES.
          CLEAR H_TEL.
          IMPORT TLINE TO LINES FROM DATABASE STXL(TX)
                                     CLIENT   I_STXL-MANDT
                                     ID       STXL_ID.
          LOOP AT LINES.
            IF LINES-TDFORMAT = '/W'.
              H_WINDOW = LINES-TDLINE.
            ENDIF.
            SEARCH LINES-TDLINE FOR H_STRING1.
            IF SY-SUBRC <> 0 AND H_STRING2 <> SPACE.
              SEARCH LINES-TDLINE FOR H_STRING2.
            ENDIF.
            IF SY-SUBRC EQ 0 AND LINES-TDFORMAT NE '/*'.
              H_POS = SY-FDPOS.
              IF NOT PA_ITEM1 IS INITIAL.
                ADD 8 TO H_POS.
              ENDIF.
              IF NOT PA_ITEM4 IS INITIAL.
                ADD 11 TO H_POS.
              ENDIF.
              H_LEN = STRLEN( PA_STR ).
              H_STRING = LINES-TDLINE+H_POS(H_LEN).
              IF H_TEL EQ 0.
                HIDE I_STXL-MANDT.
                HIDE STXL-TDNAME.
                HIDE I_STXL-TDSPRAS.
                WRITE: /001 I_STXL-MANDT,
                        005 STXL-TDNAME HOTSPOT ON,
                        036 I_STXL-TDSPRAS,
                        041 H_WINDOW(30).

  • Java Sub string urgent help

    Hi,
    I need help with the sub string.
    <fs> means field separator. (char)28.
    I have a string like(This is a very big string): "0117<fs> A<fs> 0100 <fs> <fs> <fs>admin <fs>"
    I need to get string like: "0117A0100 <fs>admin".
    Fields in the string are fixed length but some fields may change like"admin" it can be "register".
    Thanks in advance.
    Bachi.
    Edited by: bachi. on Jul 15, 2009 4:21 PM

    Sorry about that, its not home work I am working on message formatting now. Using regular expressions.
    We get the message from the socket like
    0117A0100 .admin.01010000FRAZEE.CA810FA1.admin.2 004030508342717836.1..0.0M1000030001000096..1000.
    I need to spit that message in to fields and then process the message. We need to send the response back in the same format.
    I want to split the string like this. there are some fields which are fixed length and other may change.
    0117,A,0100, ,.,admin.,0101,0000,FRAZEE,.,CA810F,A,1,.,admin,.,2, 0040,30508342717836.1..0.0M1000030001000096..1000.
    Thanks in advance.

  • A better way to search a string in a 3GB txt file

    I am looking for a string(12 characters) in a 3GB txt file. I use the file reader to go though each line and use the startwith() (that 12 characters are from the beginning of each line) to check if that line contain the string I am searching for. Is there a faster way to do it? Thank's.

    I would avoid using java to parse/search a 3 GB text file at all costs. Any java solution is going to have terrible performance and you may run into memory problems. I would recomend that you either a) develop a native method for resolving this search and just invoke it from your current java class or b) use Runtime.exec to invoke a native OS command for searching the file (like grep or find) and parse the results. ....
    I'm not even sure how I would complete that task with java exclusivly ... maybe break the file into smaller parts, then iterate through each smaller, temporary file ... I would really recomend storing your data in a different format if possible. A 3 GB text file just isn't very partical or secure.
    ... oh, to answer your original question (which I'm not sure if I all ready did), the fatest way to load the file is to wrap it into some BufferedReader. The fatest way to perform String searches is through the java.util.regex package if you have access to the 1.4 API. Other wise, just use basic String searches, as you all ready are.

Maybe you are looking for