aspose 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 OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Parsing the String " Watch "Parsing the String " New topic

Parsing the String

poornima sudharshan

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

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.
It is sorta covered in the JavaRanch Style Guide.
subject: Parsing the String