Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > use matches in string w/o Pattern

Thread Tools

use matches in string w/o Pattern

Posts: n/a
I have a problem using matches in string w/o using pattern. In the
following code, st.nextToken() returns "111-11-1111" to "s". s.matches
returns "true" to boolean "bl" and "s" still has the string value. But
after if (bl), the value of "bl" and "s" are empty, and it is always
stepping into System.out.println(s) no matter "bl" is true or false. I
don't know why after executing "if (bl)", the values of "bl" and "s"
are cleaned up. I also tried "while (bl)" and the result is the same.
Do I have to use Pattern/matches?

************************************************** **************

import java.util.*;

public class stuRec {
public static void main(String f[]) {
int i=0;
char c;
FileReader fr = new FileReader("student.txt");
BufferedReader br = new BufferedReader(fr);
StringTokenizer st;
String myline = br.readLine();
st = new StringTokenizer(myline);
while (st.hasMoreTokens()) {
String s = st.nextToken();
boolean bl =
if (bl){


} catch (IOException ioe) {
System.out.println("IO error:" + ioe ); }
Reply With Quote

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Match a pattern multiple times, returning matches, captures andoffset? Markus Fischer Ruby 9 04-08-2011 07:53 PM
How to use Regex to breakdown a pattern and use the pattern to breakdown a string ChrisC Perl Misc 4 06-25-2010 05:46 PM
searching for a pattern for multiple matches jhu Perl Misc 6 11-26-2007 10:49 AM
Assigning pattern matches to an array Graham Stow Perl Misc 15 01-01-2007 05:49 PM
Extraction of attribute values from pattern matches Peekachu Java 1 07-10-2006 07:59 PM