[484] in java-interest

home help back first fref pref prev next nref lref last post

Re: String.indexOf(String,int)

daemon@ATHENA.MIT.EDU (Michael Mills 21728)
Fri Jun 23 20:50:52 1995

From: ekim@nyquist.bellcore.com (Michael Mills 21728)
To: java-interest@java.sun.com
Date: Fri, 23 Jun 1995 20:12:45 -0400 (EDT)


Chuck,

> If you do it with a 32,766 byte string does it work? 

32000 is better. 32,766 is not as good as 32000. 100
is the same as 32766.  I changed the code a little.
Now I just change strSize. It should be above 12.

--------------- using 32000---------------------------
TEST!
CONVERTED 32000
findme
findme
THE FIRST = 16000
THE FIRST = 16000
THE FIRST = 16000
THE FIRST = 16000
THE STRING LENGTH = 6
THE FIRST = -1
findme
findme
--------------- using 32766---------------------------
TEST!
CONVERTED 32766
findme
findme
THE FIRST = 16383
THE FIRST = -1
THE FIRST = -1
THE FIRST = 16383
THE STRING LENGTH = 6
THE FIRST = -1
findme
findme

--------------- using 100 ---------------------------
TEST!
CONVERTED 100
findme
findme
THE FIRST = 50
THE FIRST = -1
THE FIRST = -1
THE FIRST = 50
THE STRING LENGTH = 6
THE FIRST = -1
findme
findme





import java.lang.system;
import java.lang.Object;
import java.io.InputStream;
import net.www.http.HttpClient;
import net.www.html.URL;
class trySearch {
    public static void main (String argv [])
    {
      int strSize = 32000;
      int findIndex = strSize / 2;
      System.out.println("TEST!");
      byte buff[] = new byte[strSize];

      for(int x=0;x<strSize;x++)
      {
        buff[x] = 'x';
      }

      buff[findIndex] = 'f';
      buff[findIndex +1] = 'i';
      buff[findIndex +2] = 'n';
      buff[findIndex +3] = 'd';
      buff[findIndex +4] = 'm';
      buff[findIndex +5] = 'e';

      String str = new String(buff,buff.length);


      System.out.println("CONVERTED "+str.length() );
      System.out.println(str.substring(findIndex +0,findIndex +6)) ;
      System.out.println(str.substring(findIndex +0,findIndex +6)) ;



      int first = str.indexOf(str.substring(findIndex +0,findIndex +6)
,0);
      System.out.println("THE FIRST = " + first);

      first = str.indexOf("findme",0);
      System.out.println("THE FIRST = " + first);

      String search = new String("findme");
      first = str.indexOf(search,0);
      System.out.println("THE FIRST = " + first);



      search = str.substring(findIndex +0,findIndex +6);
      first = str.indexOf(search,0);
      System.out.println("THE FIRST = " + first);

      byte buff2[] = new byte[6];
      buff2[0] = 'f';
      buff2[1] = 'i';
      buff2[2] = 'n';
      buff2[3] = 'd';
      buff2[4] = 'm';
      buff2[5] = 'e';

      search = new String(buff2,  buff2.length );
      System.out.println("THE STRING LENGTH = " + search.length());
      first = str.indexOf(search,0);
      System.out.println("THE FIRST = " + first);

      System.out.println(search);
      System.out.println(str.substring(findIndex +0,findIndex +6) );
    }
}




-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post