Results 1 to 2 of 2
  1. #1
    isaac.flaum is offline Member
    Join Date
    Feb 2011
    Posts
    1
    Rep Power
    0

    Default Split a string into array every 11th char

    I have this:
    String str = "000000000001111111111122222";
    String[] array = new String[3]';

    I would like a way to split str every 11 characters into array so that i would have:
    array[0] = "00000000000";
    array[1] = "11111111111";
    array[2] = "22222";

    I tried using the split method but that kept inserting pesky [] characters. Any idea how to do this?

  2. #2
    eRaaaa is online now Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default

    There are many ways to make this.

    You could use a StringBuilder, or String.substring or with split and a Regex e.g. with
    Java Code:
    		String str = "000000000001111111111122222";
    		String[] array = str.split("(?<=\\G.{11})");

Similar Threads

  1. create a 2d char array from a 1D string array
    By jschmall12 in forum New To Java
    Replies: 1
    Last Post: 04-27-2010, 09:01 PM
  2. Java split string, the first char is a space
    By new_cyber in forum New To Java
    Replies: 8
    Last Post: 12-31-2009, 01:27 AM
  3. Convert Char Array to String Array
    By Mayur in forum New To Java
    Replies: 8
    Last Post: 10-12-2009, 11:41 AM
  4. How to split a String using split function
    By Java Tip in forum java.lang
    Replies: 4
    Last Post: 04-17-2009, 08:27 PM
  5. How to split a String using split function
    By JavaBean in forum Java Tip
    Replies: 0
    Last Post: 10-04-2007, 09:32 PM

Tags for this Thread

Posting Permissions

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