Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: How to find if a sting contains another string?

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default How to find if a sting contains another string?

    Hi all,

    I cant figure out how to "search" what a sting contains. So say I am using the Scanner command to find user impute. I want to see if what the user typed contains the word "no" or the word "yes"? how would I go about doing that?? I cant find anything in the Java docs... (probibly not looking in the right place lol). All I really need is a command like .contains("yes") or something like that... (if that's it I will kill my self...)(contains doesn't work...) lol

    Thank you all!!
    deathpk


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: How to find if a sting contains another string?

    As a matter of fact, it does: String contains Javadoc

    String s = "hello world!";
    if(s.contains("hello"))
    {
        System.out.println("s contains hello");
    }

  3. #3
    Junior Member
    Join Date
    Oct 2011
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How to find if a sting contains another string?

    Quote Originally Posted by helloworld922 View Post
    As a matter of fact, it does: String contains Javadoc

    String s = "hello world!";
    if(s.contains("hello"))
    {
        System.out.println("s contains hello");
    }
    Thank you

    And I am just dumb... I see where it is now thank you for linking me to it.

    Deathpk

    CLOSED

Similar Threads

  1. Replies: 5
    Last Post: April 22nd, 2013, 07:27 AM
  2. How to find a a certain part in string
    By redzero36 in forum Java Theory & Questions
    Replies: 7
    Last Post: July 19th, 2011, 06:39 PM
  3. Sting format give more truble
    By ahmethbaai in forum Java Theory & Questions
    Replies: 1
    Last Post: December 17th, 2009, 01:19 PM
  4. Replies: 2
    Last Post: November 3rd, 2009, 06:28 AM
  5. [SOLVED] find the position of the field separator in the String---need help ASAP
    By rajesh.mv in forum Java Theory & Questions
    Replies: 6
    Last Post: August 17th, 2009, 10:33 AM