Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Oct 2009
    Posts
    51
    Thanks
    6
    Thanked 0 Times in 0 Posts

    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

  • #2
    New Coder
    Join Date
    Oct 2009
    Posts
    51
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Figured it out - used split to break up the string to get the content.

    String cookiename = str.split("\\=")[0];
    String cookievalue = str.split("\\=")[1];


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •