Results 1 to 4 of 4
  1. #1
    igorland is offline Member
    Join Date
    Jan 2013
    Posts
    25
    Rep Power
    0

    Default Splitting String and assigning tokens to variables

    Hello. Is there any way I can split a long string into two parts (with, say, 50 characters in the first part and the rest in the second part) and then assign each part to a variable? I am trying to use Guava Splitter

    Java Code:
      		for(final String token :
    			    Splitter
    			        .fixedLength(56)
    			        .split(s))	{
    But then I do not know how to assign each token to a variable.

    Thanks a lot!

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,573
    Rep Power
    12

    Default Re: Splitting String and assigning tokens to variables

    To split a String into two parts use the two String substring() methods. They return strings which can be assigned to anything you like.

    Where - as in this case - the number of bits is small and known in advance, substring() is more than straightforward than Splitter.

  3. #3
    igorland is offline Member
    Join Date
    Jan 2013
    Posts
    25
    Rep Power
    0

    Default Re: Splitting String and assigning tokens to variables

    Thanks so much! It works!

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,573
    Rep Power
    12

    Default Re: Splitting String and assigning tokens to variables

    You're welcome.

Similar Threads

  1. Splitting the string[]
    By issoa in forum New To Java
    Replies: 1
    Last Post: 02-28-2012, 07:56 AM
  2. Java string splitting and concatination
    By mc1234 in forum New To Java
    Replies: 6
    Last Post: 09-26-2011, 04:02 PM
  3. Problem splitting a string
    By sehudson in forum New To Java
    Replies: 2
    Last Post: 03-13-2011, 09:56 PM
  4. String Splitting
    By A.M.S in forum New To Java
    Replies: 1
    Last Post: 12-04-2009, 08:17 AM
  5. splitting string and replacing
    By itsme in forum New To Java
    Replies: 1
    Last Post: 12-11-2007, 04:08 PM

Posting Permissions

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