Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-13-2012, 10:08 PM   PM User | #1
billatl
New Coder

 
Join Date: Oct 2009
Posts: 51
Thanks: 6
Thanked 0 Times in 0 Posts
billatl is an unknown quantity at this point
Get Portions of String

Hello,

I need to get portions of a string and assign to variables using (I think) the substring method. Where I'm a little fuzzy is how to use the string.length() method to obtain the parts before/after a character when the string's length is variable.

For example, I would like to :

String str = "zipcode=90210";
String cookiename = "zipcode";
String cookievalue = "90210";

In the above example, it would be fairly straight forward since I already know the length of the string before & after the "=". Since my app would need to support any cookie name and value, how would I go about capturing the entire strings before & after the "="?

Thanks
billatl is offline   Reply With Quote
Old 10-15-2012, 02:44 AM   PM User | #2
billatl
New Coder

 
Join Date: Oct 2009
Posts: 51
Thanks: 6
Thanked 0 Times in 0 Posts
billatl is an unknown quantity at this point
Figured it out - used split to break up the string to get the content.

String cookiename = str.split("\\=")[0];
String cookievalue = str.split("\\=")[1];
billatl is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:06 PM.


Advertisement
Log in to turn off these ads.