• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

getting a substring from a string

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Master Rancher
Posts: 4830
74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic