I ask for help if any one know how to filter words from text file.
if the file contain(book,books,booking,..)I want the filter to retrieve only book and booking also if it contain(get and got)choose only the verb "get".

any help
Thanks.

I ask for help if any one know how to filter words from text file.
if the file contain(book,books,booking,..)I want the filter to retrieve only book and booking also if it contain(get and got)choose only the verb "get".

any help
Thanks.

Couldnt you try the contains() method for strings?

public static void main(String[] args)
  {
    //Declaration of first string
        String str1 = "Welcome to DaniWeb";
    //Returns true if and only if this string contains the specified sequence of char values.
    boolean equals1 = str1.contains("Welcome"); 
     System.out.println(equals1);
     }
}

Couldnt you try the contains() method for strings?

public static void main(String[] args)
  {
    //Declaration of first string
        String str1 = "Welcome to DaniWeb";
    //Returns true if and only if this string contains the specified sequence of char values.
    boolean equals1 = str1.contains("Welcome"); 
     System.out.println(equals1);
     }
}

Thank you for this but I need to filter random word not known words , in other way I want to clear the redundant words in a big text file which I don't know the words contained.

and how will your code while running know what to filter out? it must have a list of words stored somewhere. whether they're hardcoded or entered by reading them from an inputfile, you can still use the contains method.

whether you have:

if ( text.contains("myWord"))

or

String check = "myWord";
if ( text.contains(check))

doesn't really matter, does it?

and how will your code while running know what to filter out? it must have a list of words stored somewhere. whether they're hardcoded or entered by reading them from an inputfile, you can still use the contains method.

whether you have:

if ( text.contains("myWord"))

or

String check = "myWord";
if ( text.contains(check))

doesn't really matter, does it?

you are right , the word must be stored but in this case I will store the whole English dictionary, I need it automated or real exist program or library.

thanks.

so ... you are planning to filter out every word in the English dictionary? well ... your text might indeed end up a bit shorter than when started :)
but as been suggested earlier, the contains method will check for:
boon
boons
boondock
if (word.contains("boon"))
=> return true on all the above

so ... you are planning to filter out every word in the English dictionary? well ... your text might indeed end up a bit shorter than when started :)
but as been suggested earlier, the contains method will check for:
boon
boons
boondock
if (word.contains("boon"))
=> return true on all the above

look at the italic font if i had this part of text
"An article is a word that combines with a noun to indicate the type of reference being made by the noun. Articles specify the grammatical definiteness of the noun, in some languages extending to volume or numerical scope.The articles in the English language are the and a/an, and (in some contexts) some. 'An' and 'a' are modern forms of the Old English 'an', which in Anglian dialects was the number 'one' (compare 'on', in Saxon dialects) and survived into Modern Scots as the number 'ane'. Both 'on' (respelled 'one' by the Normans) and 'an' survived into Modern English, with 'one' used as the number and 'an' ('a', before nouns that begin with a consonant sound) as an indefinite article." the function return only one(article,language,..)and so on.

get a copy of the original text, put everything to lower cases
if ( lowerCaseText.indexOf("article") != -1 )
check for the found indexOf, if the index + "article".length is either space, a ',', a '.', ... if so, word found, if it's a letter, not found, go to the next indexOf you find.

you mean something like that?

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.