Results 1 to 8 of 8

Thread: C to JAVA

  1. #1

    C to JAVA

    Anyone know the java equivalent of strstr()?

  2. #2

    Re:C to JAVA

    http://java.sun.com/j2se/1.4.2/docs/...e-summary.html

    Dunno exactly what you're wanting offhand, but chances are real good you'll find it somewhere in here.

  3. #3

    Re:C to JAVA

    Thanks for you reply,

    But, I was looking for more of an example of how to search for a substring within a string.

  4. #4

    Re:C to JAVA

    Well the matcher would be my weapon of choice. It might be overkill if you're not used to it though. I believe the String class is what you're looking for. Note however that for this to work you must be using the String wrapper class to create full objects, rather than using primitives as strings (eg using "String s = new String("this is s&quot" instead of "string s = "this is s&quot

    http://java.sun.com/j2se/1.4.2/docs/...ng/String.html

  5. #5
    Mentor
    Join Date
    Jul 2001
    Posts
    1,666

    Re:C to JAVA

    Wow something I remember.
    Say you have

    String tester;
    tester = "this is a test string";
    tester.indexof("test"

    Will return the value 10. It gives you an integer telling you where what you are searching for starts, or -1 if it isn't in the string.
    CP

  6. #6

    Re:C to JAVA

    thanks so something like this?
    Code:
    public boolean strstr(String foo, String bar)
    {
       int x = foo.indexof(bar);
        if(x == -1)
           {
              return false;
            }
         else
            {
               return true;
             }
    }
    basically meaning I don't have to use it as an object?

  7. #7
    Mentor
    Join Date
    Jul 2001
    Posts
    1,666

    Re:C to JAVA

    Should work, few little things though. its indexOf, with a capital O, and use if x==-1, not just x=-1

  8. #8

    Re:C to JAVA

    Whoops, a couple typos there, I should really review things before I post them. Thanks for your help.

Similar Threads

  1. using JAVA
    By gohbucks69 in forum Linux - Software, Applications & Programming
    Replies: 2
    Last Post: 01-20-2005, 02:40 AM
  2. java and opera... always says invalid java directory
    By sujoki in forum Linux - Software, Applications & Programming
    Replies: 0
    Last Post: 08-26-2003, 03:54 PM
  3. how to apt-get java
    By S_D_Willie in forum Linux - General Topics
    Replies: 13
    Last Post: 11-22-2002, 12:38 AM
  4. Java
    By drizzle in forum Linux - Software, Applications & Programming
    Replies: 7
    Last Post: 01-30-2002, 03:37 PM
  5. Java & Mozilla (formerly Java and Netscape)
    By papanohair in forum Linux - General Topics
    Replies: 2
    Last Post: 01-07-2002, 08:21 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •