• Post Reply Bookmark Topic Watch Topic
  • New Topic

Finding a character in a String  RSS feed

 
rastin purr
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Is there a way to find a character in a string. Say find "?" in a string like "asddsa?asdd" or "asddss/asdd".
I tried using StringTokenizer to find delim "?" but the tokenizer doesn't seems to diferentiate "?" and "/". Any ideas?
Cheers
Ras
 
John Lee
Ranch Hand
Posts: 2545
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would write my own fuction, read in all the characters one by one, then compare them with ? or /.
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
  • I don't know what you did exactly. But the StringTokenizer does work.
  • What's wrong with String.indexOf()?
  • In more complicated cases, the regular expression support in JDK 1.4 (including several new methods in String itself) will help you.
  • Writing your own character-munching code should be strictly the last resort.
  • - Peter
     
    John Lee
    Ranch Hand
    Posts: 2545
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    How come StringTokenizer doesn't work? Maybe you can show your code.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!