Converting the case of a string

Is there a way to convert the case of a string?I have a class called Word that holds a string and an integer. The Word type is being placed into a Binary Search Tree and then I need to change the case of the string portion.hughveal
[252 byte] By [hughveala] at [2007-11-27 8:56:23]
# 1
Did you read the String API?
camickra at 2007-7-12 21:19:18 > top of Java-index,Java Essentials,Java Programming...
# 2
toUpperCase()toLowerCase()
cotton.ma at 2007-7-12 21:19:18 > top of Java-index,Java Essentials,Java Programming...
# 3
And assign the dukes you promised in the last thread to paul and that other dude.
cotton.ma at 2007-7-12 21:19:18 > top of Java-index,Java Essentials,Java Programming...
# 4
I have seen that the toLowerCase exists, but I need to make a method for this Word class in order to use it. I tried putting the characters of the string portion in a character array, but I kept getting a dereferencing error.
hughveala at 2007-7-12 21:19:18 > top of Java-index,Java Essentials,Java Programming...
# 5
Dukes have been assigned. Sorry it took so long, I am new here.
hughveala at 2007-7-12 21:19:18 > top of Java-index,Java Essentials,Java Programming...
# 6

> I have seen that the toLowerCase exists, but I need

> to make a method for this Word class in order to use

> it. I tried putting the characters of the string

> portion in a character array, but I kept getting a

> dereferencing error.

I don't understand what you did other than somewhere I guess you tried to call toLowerCase or some other method on a char probably.

Post your code.

cotton.ma at 2007-7-12 21:19:18 > top of Java-index,Java Essentials,Java Programming...
# 7

So your problem isn't really "Is there a way to convert the case of a string?", but rather, you have a bug in your code.

You'll get better responses if you're more forthcoming with the real issues.

That includes posting the actual error message you're getting, and the actual code that's causing it.

paulcwa at 2007-7-12 21:19:18 > top of Java-index,Java Essentials,Java Programming...
# 8
It was a few changes ago. I will recode it and post it for everyone to see.
hughveala at 2007-7-12 21:19:18 > top of Java-index,Java Essentials,Java Programming...
# 9

> I have seen that the toLowerCase exists, but I need to make a

> method for this Word class in order to use it. I tried putting the

> characters of the string portion in a character array, but I kept getting a dereferencing error.

Then you question isn't about converting the case of a String, Its about how to write code!

If you need further help then you need to create a "Short, Self Contained, Compilable and Executable, Example Program (SSCCE)",

see http://homepage1.nifty.com/algafield/sscce.html,

that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.

Don't forget to use the "Code Formatting Tags",

see http://forum.java.sun.com/help.jspa?sec=formatting,

so the posted code retains its original formatting.

Gee, I'm slow at the reply...

Message was edited by:

camickr

camickra at 2007-7-12 21:19:18 > top of Java-index,Java Essentials,Java Programming...
# 10
I don't want it to seem as if I was trying to hide something. The reason I didn't post the code was because I was sure if my logic was sound, and should be trying it the way I decided to go by using a character array. As soon as I recode the toLowerCase method, I will post.
hughveala at 2007-7-12 21:19:18 > top of Java-index,Java Essentials,Java Programming...
# 11
> The reason I didn't post the code was because I was sure if my logic was soundDon't assume, its wastes our time.
camickra at 2007-7-12 21:19:18 > top of Java-index,Java Essentials,Java Programming...
# 12
> > The reason I didn't post the code was because I was> sure if my logic was sound> > Don't assume, its wastes our time.Holey moley. :(Usually I am the crabby one around here. I guess the heat's getting to everyone.
cotton.ma at 2007-7-12 21:19:18 > top of Java-index,Java Essentials,Java Programming...
# 13

Also in cases like this, when you have to do things because an assignment requires you to, but these things would normally be considered awkward or extraneous (e.g., duplicating existing APIs) you should probably just announce it as such, and even quote the homework assignment in the question.

Otherwise, as you've seen, people will do the reasonable thing and point you to the API, which normally is the correct thing to do but in this scenario just wastes their time and yours.

paulcwa at 2007-7-12 21:19:18 > top of Java-index,Java Essentials,Java Programming...
# 14
> > Holey moley. :(> Usually I am the crabby one around here. I guess the heat's getting to everyone. Yes, I was surprised I didn't see a RTFM reply! :)
camickra at 2007-7-12 21:19:18 > top of Java-index,Java Essentials,Java Programming...
# 15
RTFM!Happy now?
floundera at 2007-7-21 22:50:47 > top of Java-index,Java Essentials,Java Programming...
# 16

Here is the code for the Word class I created:

public class Word

{

private String Phrase;

private int counter;

//Empty Constructor

public Word()

{

Phrase = null;

counter = 0;

}

//constructor with 2 arguments

public Word(String phr, int cnt)

{

Phrase = phr;

counter = cnt;

}

//Constructor with one argument

public Word(String phr)

{

Phrase = phr;

counter = 0;

}

//equals() method

public boolean equals(Word looking)

{

boolean status;

if(Phrase.equals(looking.Phrase)&& (counter != looking.counter))

status = true;

else

status = false;

return status;

}

//toLowerCase

public String toLowerCase(String shifter)

{

char ch;

int lng;

lng = shifter.length();

for(int i = 0; i < lng; i++)

{

ch = shifter.charAt(i);

ch = shifter.toLowerCase(ch);

}

}

//compareTo method

//toString method

public String toString()

{

String describer = Phrase + ", " + counter;

return describer;

}

//setPhrase

public void setPhrase(String p)

{

Phrase = p;

}

//setCount

public void setCount(int c)

{

counter = c;

}

//getword

public String getWord()

{

return Phrase;

}

//getcount

public int getCount()

{

return counter;

}

}

The error I get is:

Word.java:50: cannot find symbol

symbol : method toLowerCase(char)

location: class java.lang.String

ch = shifter.toLowerCase(ch);

hughveala at 2007-7-21 22:50:47 > top of Java-index,Java Essentials,Java Programming...
# 17

You're calling String.toLowerCase(charVariable)

if you look at String, you'll see that it doesn't have a call of this method that takes a character argument and returns a char.

Have a look at Character:

http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Character.html#toLowerCase(char)

petes1234a at 2007-7-21 22:50:47 > top of Java-index,Java Essentials,Java Programming...
# 18
Err never mind. Move along nothing to see here.
floundera at 2007-7-21 22:50:47 > top of Java-index,Java Essentials,Java Programming...
# 19
> Err never mind. Move along nothing to see here.?
CaptainMorgan08a at 2007-7-21 22:50:47 > top of Java-index,Java Essentials,Java Programming...
# 20
Initial post removed!
floundera at 2007-7-21 22:50:47 > top of Java-index,Java Essentials,Java Programming...
# 21
> Initial post removed!But what a post!A lengthy soliloquy on case sensitivity in Java. I was moved to tears.
cotton.ma at 2007-7-21 22:50:47 > top of Java-index,Java Essentials,Java Programming...
# 22
> A lengthy soliloquy on case sensitivity in Java. I> was moved to tears.but silent tears.
petes1234a at 2007-7-21 22:50:47 > top of Java-index,Java Essentials,Java Programming...
# 23
Thanks for all of the ridicule, and little help. After the barrage of insults I figured it out. Thanks to those that helped.
hughveala at 2007-7-21 22:50:47 > top of Java-index,Java Essentials,Java Programming...