>
count a string in sentence paragragh (string)
Welcome, Guest

by Nitin on Friday, 24 July 2009
count a string in sentence paragragh (string)


 // search=a word to count

//sent = paragragh or sentence or big string to search in

public int getFrequency(String search, String sent)
    {
        sent = sent.trim();
        search = search.trim();

        int index = 0;
        int end = 0;
        int count = 0;

        while(index != -1)
        {
            index = sent.indexOf(search,end);
            end = index + search.length();

            if(index!=-1)
            {
                if(((index == 0) && !isAfterChar(sent,end)) || ((index > 0) && !isBeforeChar(sent,index)) || ((index>0) && !isAfterChar(sent,end) && !isBeforeChar(sent,index)) || ((index==0) && sent.length()==end))
                    ++count;
            }
        }
        return count;
    }

    public boolean isBeforeChar(String st,int index)
    {
        boolean flag = false;

        if(index>0)
        {
            if(((((int)st.charAt(index-1))>64) && (((int)st.charAt(index-1))<91)) || ((((int)st.charAt(index-1))>96) && (((int)st.charAt(index-1))<123)))
            {
                flag = true;
            }
        }
        return flag;
    }

    public boolean isAfterChar(String st,int end)
    {
        boolean flag = false;

        if(st.length() > end)
        {
            if(((((int)st.charAt(end))>64) && (((int)st.charAt(end))<91)) || ((((int)st.charAt(end))>96) && (((int)st.charAt(end))<123)))
            {
                flag = true;
            }
        }
        return flag;
    }

 

Cheers :)



Blogger Image
My Blog Title

Product Engineering, software engineering company, Product Development, Product Migration, Product Re-engineering, Product Maintenance, Product Testing Commercial Application Development, Business Software development, commercial software for startups, Application Support and Maintenance, software testing Product Maintenance, Outsource product maintenance, product support and maintenance Product Migration, Product Re-engineering, product re-engineering services Product Research, Product Engineering, UI Prototyping Services Software Testing Services, Quality Assurance services, professional software testers, Load Testing, Functional Testing, Cross Platform, Browser Testing, Test Automation, Testing Tools, software quality analysis Functional Testing Services, software quality analysis, Software Testing Services, Application Testing Services, Functional Testing Types Automated Testing, Automated Testing Services, automation testing, test script development, Automation Test Tools, outsource automation testing Load Testing, Performance Testing Services, Load Testing Tools Offshore Software Development, Outsource software services, offshore outsourcing services, offshore software development services, IT outsourcing services, software quality assurance services, Offshore IT services, Custom Application Development Services, Offshore Product Engineering Benefits of IT Outsourcing, Offshore Software Development companies, offshore software development firms Outsource planning, IT outsourcing, IT development services, offshore IT companies, offshore software development Offshore Software Development, Outsource software services, offshore outsourcing services, offshore software development services, IT outsourcing services, software quality assurance services, Offshore IT services, Custom Application Development Services, Offshore Product Engineering Offshore Software Development, Outsource software services, offshore outsourcing services, offshore software development services, IT outsourcing services, software quality assurance services, Offshore IT services, Custom Application Development Services, Offshore Product Engineering