Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Parsing the String

 
poornima sudharshan
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic