Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to separate String from Delimiter?

 
Koh Khai Huat
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have saved a few set of variable into a string by adding a delimiter in between different variable data.

Example
VariableA = 1;
VariableB = 2;

Data to be written to RMS : 1|2

Now when I read the data that has been written to the RMS, how do I remove the "|" and return the variable back to the original variable preset?

Best Regards,
KKH
 
Ramender Mall
Ranch Hand
Posts: 311
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well,
One way is to use indexOf('|') and substring()(both String Class function) and extract the '1' (or '2', or anything)....

And then use Wrapper Classes....
For example, if you want to store '1' as an int, you use "Integer" class' functions. Either create its object with string "1" as an argument or use static function valueOf(). And after that use intValue() to get the int value.
For the exact syntaxes of these methods, refer to MIDP API's specification, in the documentation of J2ME.

I, dont know a shorter way, although I wud like to.....In case you find out any shorter way of converting a String to int, plz post it here.

Ramy...
 
Koh Khai Huat
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Man that really helps

regards
 
Rashid Mayes
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is an additional example. It shows parsing records as they are read from the record store.



There is also method gets an int value from the resulting hash of name value pairs.



the entire src is posted at http://j2me.astrientlabs.com/appdetails.html?id=30
 
Ramender Mall
Ranch Hand
Posts: 311
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx Jim,

this second approach is really helpful

Ramy...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic