Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 19th, 2006, 2:44 AM   #1
Riddick
Newbie
 
Join Date: Sep 2006
Posts: 14
Rep Power: 0 Riddick is on a distinguished road
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.
Riddick is offline   Reply With Quote
Old Nov 19th, 2006, 2:54 AM   #2
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 837
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
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.
titaniumdecoy is offline   Reply With Quote
Old Nov 19th, 2006, 3:43 AM   #3
Jimbo
Battle Programmer
 
Jimbo's Avatar
 
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 747
Rep Power: 3 Jimbo is on a distinguished road
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 <
__________________
<insert disclaimer here>
<insert shameless plug for Visual Studio here>
Jimbo is offline   Reply With Quote
Old Nov 19th, 2006, 4:02 AM   #4
Riddick
Newbie
 
Join Date: Sep 2006
Posts: 14
Rep Power: 0 Riddick is on a distinguished road
thanks for the replys. I need to find html tags in a string so the

c.charAt(0) == '<'

method should be sufficient.
Riddick is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:37 PM.

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