• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getting a substring from a string

 
Avi Sridhar
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,

Please help me out with this .

The below URL is a String

&cardId=11084430&batchId=10&promotionId=xxxx&promoterId=x&status=dormant&cardValue=xx.xx&key=DA7FEBA4F6F8A2E28FC773BE429FBBA1.grovepc.3

&cardId=11084430&batchId=1&promotionId=xxxx&promoterId=x&status=dormant&cardValue=xx.xx&key=DA7FEBA4F6F8A2E28FC773BE429FBBA1.grovepc.3

i am trying to get batchId=10 and batchId=1 from the above string

this is the code i used



Every time i get prizeDesc = prize description 1 printed,

why is it that it is not differenciating the batchId=1 and batchId=10. Please let me know

any alternatives please.

thanks
 
Bob Good
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
batchId=10 contains the string batchId=1
You could test for batchId=10 first

Or perhaps use a StringTokenizer class.
[ March 07, 2008: Message edited by: Bob Good ]
 
Avi Sridhar
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bob Good:
batchId=10 contains the string batchId=1
You could test for batchId=10 first

Or perhaps use a StringTokenizer class.

[ March 07, 2008: Message edited by: Bob Good ]



Thanks Bob,

will try that out
 
Rob Spoor
Sheriff
Pie
Posts: 20611
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String.split should suffice:

This even allows you to create a Map out of all options, although you must keep in mind that a single key can occur multiple times in these kinds of request parameters.
 
Avi Sridhar
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rob Prime:
String.split should suffice:

This even allows you to create a Map out of all options, although you must keep in mind that a single key can occur multiple times in these kinds of request parameters.


Thanks, Will try that out too


Thanks for the reply.
 
Bill Shirley
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would split the string by &
take that collection and split each by =
and put all those in a Map

then process to your heart content with much more readable code
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also use a regular expression:

Whatever the batch ID number is, it becomes group 1 in the pattern, because it's inside the first (and only) pair of parentheses listed in the pattern.
[ March 07, 2008: Message edited by: Mike Simmons ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic