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

Parsing Strings in Midlet

 
Danish Shaukat
Ranch Hand
Posts: 341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi !
I have a string something like this:
StockID-NUMBER+StockName-ANY#http://www.myserver.com/servlet/myservlet
I want to parse it so that I get two separate strings
1- http://www.myserver.com/servlet/myservlet //URL
2- StockID-NUMBER+StockName-ANY //TextFields
Then I would like to separate the second string so that I can create textfields with name StockID and input type NUMBER. Also there is this second textfield with name StockName and with input type ANY.
I plan to create textfields based on this data.
StringTokenizer class is not present in CLDC 1.0. So, I don't think I can parse this using methods of String class. Any suggetions on how to do this in a midlet...
Danish
 
a sanjuan
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wouldn't String.substring() suit your purpose?
 
Danish Shaukat
Ranch Hand
Posts: 341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The entire string would not be the same ...
The string would be read from somewhere and the screen will be displayed depending on that string.
You see, you can always change this string to have any number of text fields. So as a programmer I don't know the indexes of characters etc. I don't even know the length of the string...
Danish
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You want to use something like this

Mark
 
a sanjuan
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yep, exactly right...use indexOf to pinpoint the location of a unique character that separates what will be the two substrings, then cut it using substring(). btw, i would suggest you get a core java book on J2SE or Java in general (don't just depend on a J2ME book). or visit sun's api docs on the web at javasoft.com
 
Danish Shaukat
Ranch Hand
Posts: 341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi !
Finally did it using loops and if statements with methods of the String class.
Thanks for all comments.
Danish
 
Orika Akawana
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. You can simply take the StringTokenizer class from J2SDK
2. You can take ANY regexp library (as small as you can find) and use it with j2me. I think it will take 15-20 min. to cerrect errors like float usage
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic