The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Campbell Ritchie:
You need to go through the regular expressions part of the Java Tutorials. The * is a metacharacter, so you might need to escape it.
The replaceAll method won't tell you whether your String contained those letters; contains will, but you would have to use it thrice to pick up A b or *.
Originally posted by Piet Verdriet:
@OP: try this:
[ August 14, 2008: Message edited by: Piet Verdriet ]
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Kuldeep Yadav:
You can Try This
Thanks
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Ilja Preuss:
How is that going to help?
Originally posted by Gopu Akraju:
I am trying to find whether letters A,b or * exists in a string.
But it doesnot seem to work. Please let me know.
Will do next time I need a regex.Originally posted by Piet Verdriet:
It appears you should also go through the regex tutorial since '*' has no special meaning inside a character class.
[ August 14, 2008: Message edited by: Piet Verdriet ]
What is the result of
"C".replaceAll("[Ab*]","").length()
?
Originally posted by Gopu Akraju:
Sorry Mike, something went wrong in copying the codes as my real variable's name is different.
works. Thanks for the clarification.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Ilja Preuss:
Piet, there exists at least one String for which your code is giving the wrong result. (Hint: think of a very minimal border case.)
Originally posted by Ilja Preuss:
Piet, there exists at least one String for which your code is giving the wrong result. (Hint: think of a very minimal border case.)
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Ilja Preuss:
OK, that I get for not writing tests for my assumptions. I was wrong. Sorry. My excuse is that I didn't have enough sleep... (I was thinking of the empty String, of course.)
You know what, I'll take that as an argument that the code isn't expressive enough, and that my Matcher idea is better
No, seriously, sorry again for tormenting you unnecessarily.
Originally posted by Mike Simmons:
Just for completeness, the other solution I mentioned is to modify the original code thus:
Comparing the length to zero made no sense. ...
Originally posted by Mike Simmons:
...
I was tying up a loose end:
...
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |