File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Parsing the String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Parsing the String " Watch "Parsing the String " New topic
Author

Parsing the String

poornima sudharshan
Greenhorn

Joined: May 18, 2001
Posts: 18
public DataInfo[] criteriaFind( String criteria ) throws
DatabaseException {
int numberOne = 1;
int numberTwo = 2;
int aIndex, bIndex;
String first, second, firstField, secondField;
aIndex = criteria.indexOf( '=' );
firstField = criteria.substring( 0, aIndex );
bIndex = criteria.indexOf( ',' );
first = criteria.substring( aIndex + numberTwo,
bIndex - numberOne );
aIndex = criteria.lastIndexOf( '=' );
secondField = criteria.substring( bIndex + numberOne,
aIndex );
bIndex = criteria.length();
second = criteria.substring( aIndex + numberTwo,
bIndex - numberOne );
}
Strings first & second represent the values in the Query Column and
Strings first field & second field represent the field names.
Is this parsing Okay,
Or is there a better way to do it?

Thanks for any reply.
SMK Reddy
Greenhorn

Joined: Jun 03, 2001
Posts: 20
I am sure you can do it better then this. The current implementation you have created is not a generalized and is more specific to a criteria which is here
�Column Name = �value�, Column name=�value��.
The current implementation is limited to two columns. What if a user wants to search a record with more then two columns or with only one column? I.e
Criteria string
Column name=�value�,Column name=�value�, Column Name=�value�
Or The Criteria string is
Column name =�value�.

A tip
Use string tokenizer (StringTokenizer) and hash table(Hashtable) class to parse and hold the column name and value pairs.
Then compare it with the Database record column values.
 
jQuery in Action, 2nd edition
 
subject: Parsing the String
 
Similar Threads
Adding elements of two arrays
While and Do-While Question
can any one explain me call by value with one sample program
Strings "equality"
Custom Bean Validator Not Called