Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Java (http://www.programmingforums.org/forum17.html)
-   -   Looking for a < in a string help (http://www.programmingforums.org/showthread.php?t=11936)

Riddick Nov 19th, 2006 2:44 AM

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.

titaniumdecoy Nov 19th, 2006 2:54 AM

:

c.charAt(0) == '<'
I believe that is what you are looking for.

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));
Lastly, please use code tags when posting in the future.

Jimbo Nov 19th, 2006 3:43 AM

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 <");

  }
}

output:
:

jimmy@vera ~/code/randomStuff $ java bleh
"something<else" has a <


Riddick Nov 19th, 2006 4:02 AM

thanks for the replys. I need to find html tags in a string so the

:

c.charAt(0) == '<'

method should be sufficient.


All times are GMT -5. The time now is 2:00 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC