![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Sep 2006
Posts: 14
Rep Power: 0
![]() |
Looking for a < in a string help
I've got an if statemtent that returns true when whitespace is found at an indexed point in a string.
if(Character.isWhitespace(c.charAt(0))) { return true } I want to do the same kind of thing if a < is found. Is there a similar way to do this? Any help would be great. |
|
|
|
|
|
#2 |
|
Expert Programmer
|
c.charAt(0) == '<' If you are searching a string for a particular character, you should use the indexOf methods of String instead. Additionally, you can condense the code fragment you provided to one line: return Character.isWhitespace(c.charAt(0)); |
|
|
|
|
|
#3 |
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 747
Rep Power: 3
![]() |
You could test string.indexOf('<')!=-1, or you could just use the contains method:
class bleh
{
public static void main(String [] args)
{
String s = "something";
String t = "something<else";
if(s.contains("<"))
System.out.println("\"" + s + "\" has a <");
if(t.contains("<"))
System.out.println("\"" + t + "\" has a <");
}
}jimmy@vera ~/code/randomStuff $ java bleh "something<else" has a <
__________________
<insert disclaimer here> <insert shameless plug for Visual Studio here> |
|
|
|
|
|
#4 |
|
Newbie
Join Date: Sep 2006
Posts: 14
Rep Power: 0
![]() |
thanks for the replys. I need to find html tags in a string so the
c.charAt(0) == '<' method should be sufficient. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| C# corruption!!! | Kilo | C++ | 32 | May 21st, 2006 8:44 PM |
| Problems with String to MD5 Conversion | emdiesse | Visual Basic .NET | 0 | Feb 2nd, 2006 10:25 AM |
| Array issues :( | Alo Tsum | Java | 10 | Nov 26th, 2005 5:45 PM |
| A standards question, optional inputs into Methods | Arla | C# | 4 | Apr 27th, 2005 10:38 PM |
| replace space with ' * ' | TecBrain | C++ | 15 | Apr 13th, 2005 12:32 PM |