if( message.contains( this.getNick() )) {
String substr = message.substring( 0, (this.getNick().length()));
String botname = this.getNick();
if( substr.equals( botname ) ) {
message = message.substring( this.getNick().length() );
} else {
message = message.replace( this.getNick(), "you" );
}
ChanMsg(channel,message);
}
[java] String Comparison
Use the String class compareTo function or equals function I believe. I tend to use the compareTo function more
if(firstString.compareTo(secondString) == 0)
{
// strings are the same
}
Look at a previous post.... this was answered recently. == on string compares the actual string objects for equality, not the string contents.
if(firstString.compareTo(secondString) == 0)
{
// strings are the same
}
Look at a previous post.... this was answered recently. == on string compares the actual string objects for equality, not the string contents.
Quote:Original post by ErUs
my problem is that when substr and botname = the same thing ( i have debugged and checked ) it still does the else code :(.
Hmm that's weird. Are you sure they're really equal? Note that .equals is case-sensitive, so if one string is "joe" and the other string is "Joe", then it will return false.
i changed them both toLower() and used with compareTO() and now it seems to work allright :)
thanks guys.
[edit]
also can anyone point me to a tutorial that shows me how i can write a whole object/class to a file and read it again?
thanks guys.
[edit]
also can anyone point me to a tutorial that shows me how i can write a whole object/class to a file and read it again?
look at www.onjava.com... there are tutorials for objectpersistence... search for jdo and you will find some tutorials... search for jdo in google and you will get some comparisons because there are some more tools for such activities...
Or just declare your top most super class as Serializable and use an ObjectOutputStream, and ObjectInputStream. The only draw back is that you can't searialize static member variables -- and there is little to no way around this. My philosophy is just not to use static member variable, anyway, so ObjectStream (output/input) are still options for me.
See java.io.ObjectInputStream, and java.io.ObjectOutputStream in the SDK, and check the Java Tutorial. Also most of the java.util.* classes are already Serializable, so you don't have to worry too much there.
L-
See java.io.ObjectInputStream, and java.io.ObjectOutputStream in the SDK, and check the Java Tutorial. Also most of the java.util.* classes are already Serializable, so you don't have to worry too much there.
L-
Quote:Original post by ErUs
i changed them both toLower() and used with compareTO() and now it seems to work allright :)
thanks guys.
[edit]
also can anyone point me to a tutorial that shows me how i can write a whole object/class to a file and read it again?
Also there is a Comparator in the String class, that is case insensitive. So you could also write something like this:
if (String.CASE_INSENSITIVE_ORDER.compareTo(lhs, rhs) == 0) { // ... do something here}
L-
Edit: Forgot the .compareTo method call.
[Edited by - Lucidquiet on August 29, 2005 7:22:14 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement