Strings help!!

I am doing a gui program.
How do i sort the words which have only the letter'e' in them??
Suppose i have the string,"Hello is a pleasing word"
I want only the words
1)Hello
2)Pleasing
HOW DO I DO THIS WITHOUT USING ARRAYS??????.
Ok and i have to write this in a method.

Here is the method's headerand it 's description
//Returns a string that concatenates all "offending"
// words from text that contain letter; the words are
// seperated by '
' characters; the returned string
// does not contain duplicate words: each word occurs
// only once; there are no punctuation or whitespace
// characters in the returned string

public String allWordsWith(char letter)

Comments

  • : I am doing a gui program.
    : How do i sort the words which have only the letter'e' in them??
    : Suppose i have the string,"Hello is a pleasing word"
    : I want only the words
    : 1)Hello
    : 2)Pleasing
    : HOW DO I DO THIS WITHOUT USING ARRAYS??????.
    : Ok and i have to write this in a method.
    :
    : Here is the method's headerand it 's description
    : //Returns a string that concatenates all "offending"
    : // words from text that contain letter; the words are
    : // seperated by '
    ' characters; the returned string
    : // does not contain duplicate words: each word occurs
    : // only once; there are no punctuation or whitespace
    : // characters in the returned string
    :
    : public String allWordsWith(char letter)
    :

    Hai, Here is your allWordsWith function as you dreamed............!

    public static String allWordsWith(String Text, char letter) {
    String str = "", tmp, test = String.valueOf(letter);
    int i = 0, j = -1;
    do {
    i = Text.indexOf(' ', j + 1);
    if (i == -1) {
    if (j < Text.length()) {
    tmp = Text.substring(j + 1, Text.length());
    if (tmp.contains(test) && str.contains(tmp) != true) {
    str = str + tmp + '
    ';
    }
    }
    break;
    }
    tmp = Text.substring(j + 1, i);
    if (tmp.contains(test) && str.contains(tmp) != true) {
    str = str + tmp + '
    ';
    }
    j = i;
    } while (true);
    return str;
    }

    This function takes two arguments, one a String Text and other a char letter. Returns only words containing the given letter and without any repetition.

    Good luck.
    But don't forget to thank me..........................................!
  • THANNNNNNKKKKKKKKKKKKK YYYYYYYYYYYYYYOOOOOOOOOOOOOOOUUUU but can u explain the logic in the loop please????
    Oh and by the way all works fine but for the puncuation part!!!
    If i have a string,"[u]Hello,[/u] is a good and, a [u]pleasing,[/u] word.
    The output will be:
    1)Hello[b],[/b]
    2)pleasing[b],[/b]

    So how do i remove the commas and other puncuation marks???
  • Welll thanks for all that information and best of luck............?


    : : I am doing a gui program.
    : : How do i sort the words which have only the letter'e' in them??
    : : Suppose i have the string,"Hello is a pleasing word"
    : : I want only the words
    : : 1)Hello
    : : 2)Pleasing
    : : HOW DO I DO THIS WITHOUT USING ARRAYS??????.
    : : Ok and i have to write this in a method.
    : :
    : : Here is the method's headerand it 's description
    : : //Returns a string that concatenates all "offending"
    : : // words from text that contain letter; the words are
    : : // seperated by '
    ' characters; the returned string
    : : // does not contain duplicate words: each word occurs
    : : // only once; there are no punctuation or whitespace
    : : // characters in the returned string
    : :
    : : public String allWordsWith(char letter)
    : :
    :
    : Hai, Here is your allWordsWith function as you dreamed............!
    :
    : public static String allWordsWith(String Text, char letter) {
    : String str = "", tmp, test = String.valueOf(letter);
    : int i = 0, j = -1;
    : do {
    : i = Text.indexOf(' ', j + 1);
    : if (i == -1) {
    : if (j < Text.length()) {
    : tmp = Text.substring(j + 1, Text.length());
    : if (tmp.contains(test) && str.contains(tmp) !=
    : true) {
    : str = str + tmp + '
    ';
    : }
    : }
    : break;
    : }
    : tmp = Text.substring(j + 1, i);
    : if (tmp.contains(test) && str.contains(tmp) != true) {
    : str = str + tmp + '
    ';
    : }
    : j = i;
    : } while (true);
    : return str;
    : }
    :
    : This function takes two arguments, one a String Text and other a
    : char letter. Returns only words containing the given letter and
    : without any repetition.
    :
    : Good luck.
    : But don't forget to thank
    : me..........................................!
    :

  • yeah but what about the puncuation marks??
  • : yeah but what about the puncuation marks??
    :

    Uhmmmmmmmmmmmmmm...........

    You people expecting too much from me.

    Here is the logic.

    Our allWordsWith(String Text,char letter) function takes two arguments of String and char. Here 'String Text' is the source and 'char letter' is to be searched for.

    First this function converts given string into words(i.e parts of string seperated by a 'space'). Each word is stored into a String variable [b]'str'[/b] seperated by a new line charecter [b]'
    '[/b]. Before storing, it checks whether the word contains the given letter and whether our [b]'word'[/b] is not added previously. This checking is done through the statement

    if (tmp.contains(test) && str.contains(tmp) != true)

    This procedure is repeted till the end of the [b]String Text[/b].

    Now about your new problems. You have to check whether the word ends with a punctuation mark. For this add another [b]if [/b] statements in the above if clause.

    I hope you guis got the IIIIdea..... and can do remaining.........

    hello1212 I got your Thank You.

    Wish you good programing daysssssssssssss.......................

    Don't forget the thanks.
  • Yeah,but what will be the condition???
    is this correct??

    if( str.contains(",")||str.contains(".")||str.contains("!") != true)
  • : Yeah,but what will be the condition???
    : is this correct??
    :
    : if( str.contains(",")||str.contains(".")||str.contains("!") != true)
    :

    Not [b]str[/b] we copied a word to [b]tmp[/b]. So you have to check whether [b]tmp[/b] contains any punctuation marks. So it should be as follows

    if( tmp.contains(",")||tmp.contains(".")||tmp.contains("!") == true)

    If the condition is true then you have to remove the punctuation Okkkkkk...
    So we have to make a change in tmp. So add following code before adding [b]tmp[/b] into [b]str[/b]

    if( tmp.contains(",")||tmp.contains(".")||tmp.contains("!") == true){
    tmp=tmp.substring(0,tmp.length-1);
    }

    Don't forget to add the above code in both if statements.
    __________________________________________________________________________
    Okkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk?
    --------------------------------------------------------------------------


    With Regards,
    Vibin Varghese
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories