import java.util.*;
class FindString
{
    public static void main(String arg[])
    {
        Scanner ob=new Scanner(System.in);
        String st="I am a student, you're also a .";
        String search;
        String st2="";
        String st3="";
        int i,c=0;
        System.out.println(st);
        System.out.println("Enter your word to search: ");
        search=ob.next();
        do
        {
            i=st.indexOf(search);
            if(i!=-1)
            {
                st2=st.substring(0,i);
                st2+=st3;
                st2+=st.substring(i+search.length());
                c=c+1;
                st=st2;
            }
        }while(i!=-1);
        System.out.println("Found=" + c);
    }
}

Sorry for all friends, that i could use the bb tag code. Wish you all feel me .

Java-specific BB Code.

[code=JAVA]
paste code here
[/code]

Non-Java-specific BB Code.

[code]
paste code here
[/code]

class FindString
{
    public static void main(String arg[])
    {
        Scanner ob=new Scanner(System.in);
        String st="I am a student, you're also a .";
        String search;
        String st2="";
        String st3="";
        int i,c=0;
        System.out.println(st);
        System.out.println("Enter your word to search: ");
        search=ob.next();
        do
        {
            i=st.indexOf(search);
            if(i!=-1)
            {
                st2=st.substring(0,i);
                st2+=st3;
                st2+=st.substring(i+search.length());
                c=c+1;
                st=st2;
            }
        }while(i!=-1);
        System.out.println("Found=" + c);
    }
}

I don't understand what you're trying to do.

Member Avatar for harsh2327

Please explain your problem properly. Cant get it what you want.


From what I have understood... to find whether a string that ends with "," or ".",
eg.

String str = "Hello World.";
if(str.charAt(str.length-1)==',' || str.charAt(str.length-1)=='.')
{
    // Your Code
}

Hey friend from my willing is i want to find a string like
E.g. String str="Hello World.";
and let the user enter the word they wish to. Right after then if the user enter "World" i want my code return Found =1 and if they enter "World." it also the same. Wish you get it!

Please explain your problem properly. Cant get it what you want.


From what I have understood... to find whether a string that ends with "," or ".",
eg.

String str = "Hello World.";
if(str.charAt(str.length-1)==',' || str.charAt(str.length-1)=='.')
{
    // Your Code
}

Huh? What's wrong with the "endsWith" method of String?

commented: Common sense prevails! +22
Member Avatar for harsh2327

Sorry for the late reply .. was away from a PC


you can endsWith() use that also ... no harm

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.