Results 1 to 2 of 2
  1. #1
    shibincse is offline Member
    Join Date
    Dec 2013
    Location
    Chennai
    Posts
    1
    Rep Power
    0

    Red face String matching program

    Hi folks,

    Here i got a program which check strings
    eg;
    String1="abcdefg"
    string2="ce";

    there are two strings ,we need to find out the characters in string2 is available in string1

    does not matter the length and order of string2

    This is my program for the question
    Java Code:
    class stringPra{
    	public static void main(String arg[]){
    		String a1=new String("abcdefg");
    		String a2=new String("a");
    		String a3,a5;
    		StringBuilder a4=new StringBuilder("");
    		char[] convert,compare;
    		compare=a2.toCharArray();//converting to array of char
    		convert=a1.toCharArray();//converting to array of char
            loop1:
    		for(int i=0;i<convert.length;i++)
    		    {
    		loop2:
    			for(int j=0;j<compare.length;j++)
    			{
    			if(compare[j]==convert[i]){	
    				a3=Character.toString(compare[j]);
    				a4.append(compare[j]);
    			continue loop2;
    			}}}
    		 a5=new String(a4);
    		if(a2.equals(a5))
    		{
    		System.out.println("String found");
    		}
    		else
    			System.out.println("String does not found");
    	}}
    The output is string found

    i requires a wise answer

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,730
    Blog Entries
    7
    Rep Power
    21

    Default Re: String matching program

    Take a look at the String.indexOf( ... ) method in the String class.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Replies: 2
    Last Post: 01-13-2012, 03:13 PM
  2. Please Help me regarding String pattern matching
    By theyoung in forum New To Java
    Replies: 11
    Last Post: 11-08-2011, 03:59 AM
  3. A beginner's question on String matching
    By nassar in forum New To Java
    Replies: 28
    Last Post: 05-23-2010, 03:44 PM
  4. String matching a pattern
    By vividcooper in forum New To Java
    Replies: 7
    Last Post: 01-07-2010, 11:30 PM
  5. regular expressions and string matching
    By DennyLoi in forum New To Java
    Replies: 1
    Last Post: 11-16-2007, 11:15 AM

Posting Permissions

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