String to 2D array

Hello
I have large string like this:
TITLE
n1
string1-1
string1-2
string1-3
n2
string2-1
string2-2
string2-3
n3
string3-1
string3-2
string3-3
n99
string99-1
string99-2
string99-3
And I want to create array:
n1 string1-1 string1-2 string1-3
n2 string2-1 string2-2 string2-3
I have tried using Spreadsheet to Array but haw to define delimiter
Any Suggestions?
Solved!
Go to Solution.

You can convert the String to a 1D Array and then reshape that to get a 2D Array. If you are sure about the number of elements thats is going to proceed after n then try this method.
The best solution is the one you find it by yourself
Attachments:
String to 2D.vi ‏7 KB

Similar Messages

  • How to get a string or byte array representation of an Image/BufferedImage?

    I have a java.awt.Image object that I want to transfer to a server application (.NET) through a http post request.
    To do that I would like to encode the Image to jpeg format and convert it to a string or byte array to be able to send it in a way that the receiver application (.NET) could handle. So, I've tried to do like this.
    private void send(Image image) {
        int width = image.getWidth(null);
        int height = image.getHeight(null);
        try {
            BufferedImage buffImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
            ImageIcon imageIcon = new ImageIcon(image);
            ImageObserver observer = imageIcon.getImageObserver();
            buffImage.getGraphics().setColor(new Color(255, 255, 255));
            buffImage.getGraphics().fillRect(0, 0, width, height);
            buffImage.getGraphics().drawImage(imageIcon.getImage(), 0, 0, observer);
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            JPEGImageEncoder jpeg = JPEGCodec.createJPEGEncoder(stream);
            jpeg.encode(buffImage);
            URL url = new URL(/* my url... */);
            URLConnection connection = url.openConnection();
            String boundary = "--------" + Long.toHexString(System.currentTimeMillis());
            connection.setRequestProperty("method", "POST");
            connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
            String output = "--" + boundary + "\r\n"
                          + "Content-Disposition: form-data; name=\"myImage\"; filename=\"myFilename.jpg\"\r\n"
                          + "Content-Type: image/jpeg\r\n"
                          + "Content-Transfer-Encoding: base64\r\n\r\n"
                          + new String(stream.toByteArray())
                          + "\r\n--" + boundary + "--\r\n";
            connection.setDoOutput(true);
            connection.getOutputStream().write(output.getBytes());
            connection.connect();
        } catch {
    }This code works, but the image I get when I save it from the receiver application is distorted. The width and height is correct, but the content and colors are really weird. I tried to set different image types (first line inside the try-block), and this gave me different distorsions, but no image type gave me the correct image.
    Maybe I should say that I can display the original Image object on screen correctly.
    I also realized that the Image object is an instance of BufferedImage, so I thought I could skip the first six lines inside the try-block, but that doesn't help. This way I don't have to set the image type in the constructor, but the result still is color distorted.
    Any ideas on how to get from an Image/BufferedImage to a string or byte array representation of the image in jpeg format?

    Here you go:
      private static void send(BufferedImage image) throws Exception
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        ImageIO.write(image, "jpeg", byteArrayOutputStream);
        byte[] imageByteArray = byteArrayOutputStream.toByteArray();
        URL url = new URL("http://<host>:<port>");
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setDoOutput(true);
        connection.setRequestMethod("POST");
        OutputStream outputStream = connection.getOutputStream();
        outputStream.write(imageByteArray, 0, imageByteArray.length);
        outputStream.close();
        connection.connect();
        // alternative to connect is to get & close the input stream
        // connection.getInputStream().close();
      }

  • Converting XML String to MessageElement array

    Hi,
    I am trying to call a .NET web service from my Java client. I used WSDL2Java to generate the java classes for calling the .NET web service. The generated classes to call the service expects an array of org.apache.axis.message.MessageElement objects. I have a string representing an XML document which looks like this:
    String xmlString = "<Results><Adjustments><Adjustment><RebuildAdjustmentID>16</RebuildAdjustmentID><IsBasicAdjustment>true</IsBasicAdjustment><AdjustmentType>stone/AdjustmentType><Title>External walls</Title></Adjustment></Adjustments></Results>"
    I have tried converting the string into an array of MessageElement objects by the following way:
    MessageElement[] m = new MessageElement[1];
    Document XMLDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(result2.toString())));
    m[0] = XMLDoc.getDocumentElement();
    However I keep getting the following message returned from the service:
    "Object reference not set to an instance of an object"
    I have tried a handful of ways but keep getting this same error. I have searched the web for hours looking for a solution to this problem without success so any help/ideas much appreciated,
    Thanks.
    Paul

    Any updates on this?
    I am facing a similar problem.

  • Creating a String from an array of characters.

    Hi,
    i'm trying to make a string from an array of characters, this i've managed:
    char data[] = new char[x];
    String str = new String(data);My problem is this: Let's say the array of characters has space for 10 chars, but i only input 5, when i convert it to a string, the 5 characters show up fine, but the last remaining characters show up as little boxes ( [] [] [] [] [] ) .
    It there a way to remove these?
    Thanks in advance
    Mike

    jverd wrote:
    georgemc wrote:
    String str = new String(data).trim();
    Does the null character count as whitespace?Seems to. Actually, I'm getting different results depending on the compiler used.
    public static void main(String[] args) {
              char[] c = new char[10];
              for(int i = 0; i < 5; i++) {
                   c[i] = (char) ('a' + i);
              String first = new String(c);
              System.err.println("[" + first  + "]");
              System.err.println(first.length());
              String second = new String(c).trim();
              System.err.println("[" + second  + "]");
              System.err.println(second.length());
         }ECJ-compiled output:
    >
    [abcde
    10
    [abcde]
    5
    >
    javac-compiled output:
    >
    [abcde]
    10
    [abcde]
    5
    >
    Odd

  • Converting a String to an array list

    Anyone know how i turn a string into an array list of characters?

    check out the java.lang.String API for the method toCharArray() for your answer.

  • Converting String to an Array

    Hi..
    Need some help on how to go about converting a given string into an array. I belive there is a way in java to chop the string into chars and then feed the chars into an array. Anyone that can help me out on what methods to look for?

    Hi ,
    Did you get answer of your query If yes then pls send
    me the code at my e-mail id
    [email protected]
    I will be thankful to you
    Regds,
    SureshSomeone else who likes to get info on breast implants and penis extensions in their email account.

  • How do I split a comma delimited string into an array.

    I have a string that I am passing into a function that is Comma delimited. I want to split the string into an array. Is there a way to do this.
    Thanks in advance.

    trouble confirmed on 10gR1 and 10gR2
    works with 'a,b,c'  and also with  '  "1"  , "2"  ,  "3"  '
    does not work with '1,2,3' 
    throwing ORA-6512                                                                                                                                                                                                                                                                                                                           

  • How to break up a String into multiple array Strings?

    How do I break up a string into a bunch of String arrays after the line ends.
    For example,
    JTextArea area = new JTextArea();
    this is a string that i have entered in the area declared above
    now here is another sting that is in the same string/text area
    this is all being placed in one text field
    Sting input = area.getText();
    now how do I break that up into an array of strings after each line ends?

    Ok I tested it out and it works.
    So for future refrence to those that come by the same problem I had:
    To split up a string when using a textfield or textarea so that you can store seperate sections of the string based on sperate lines, using the following code:
    String text = area.getText() ;
    String[] lines = text.split("\n") ;
    This will store the following
    this is all one
    entered string
    into two arrays
    Cheers{
    Edited by: watwatacrazy on Oct 21, 2008 11:06 AM
    Edited by: watwatacrazy on Oct 21, 2008 11:16 AM
    Edited by: watwatacrazy on Oct 21, 2008 11:16 AM

  • Converting String to byte array

    Hi,
    There is a code for converting String to byte array, as follows:
         public byte[] toByteArray(String s)
              char[] c = s.toCharArray();
              int len = c.length;
              byte[] b = new byte[len * 2];
    for ( int i = 0 ; i < len ; i++ )
         b[i * 2] = (byte)(c);
         b[(i * 2) + 1] = (byte)(c[i] >> 8);
    return b;
    But this isn't doing the conversion properly. For example, for the � (euro) symbol, it converts to some other unreadable symbol. Also, same is the case for square brackets. Any idea why this' so? What's wrong with the above code?
    The encoding format is UTF-8.
    Thanks.

    > In fact, I tried with String.getBytes() too, but leads to the same problem, with those specific symbols.
    Did you try the String.getBytes(String charsetName) method?
    Both methods have been around since Java 1.1.
    It's an extremely important skill to learn to read the API and become familiar with the tools you will use to program Java. Java has an extensive set of online documentation that you can even download for your convenience. These "javadocs" are indexed and categorized so you can quickly look up any class or method. Take the time to consult this resource whenever you have a question - you'll find they typically contain very detailed descriptions and possibly some code examples.
    Java� API Specifications
    Java� 1.5 JDK Javadocs
    Best of luck!
    ~

  • Convert a string to an array of 16bit unsigned integers

    I have a string represented in hex format, how can I convert this to an array of 16 bit unsigned integers?
    I know I can use string to byte array to easily convert it to 8 but unsigned integers, is there a simple way for 16 bit unsigned integers?
    Solved!
    Go to Solution.

    hydzik wrote:
    I have a string represented in hex format, how can I convert this to an array of 16 bit unsigned integers?
    I know I can use string to byte array to easily convert it to 8 but unsigned integers, is there a simple way for 16 bit unsigned integers?
    While your description is somewhat vague and not very clear, I think the typecast solution from the previous poster may not be what you look for. You may more likely look for something along these lines:
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions
    Attachments:
    HexToU16.png ‏17 KB

  • Passing a String to an array.

    Hi there I am trying to pass an Input String to an Array at a position queueNext, which is currently zero, and with the loop it increases or increases when u remove a word form the queue, for sum reason I get an error about incompatible types.
    here is the chunk of code.
    boolean AddToQueue (String value_to_add)
          if (QueueIsFull())
                    return false;
          else
               queueArray[queueNext] = value_to_add;       
                                                                // add new value to end
               queueNext = (queueNext + 1);
                                                                // move end of queue
               queueEntries ++;                               //now have one more entry
               return true;                                    // return success
      }

    Could you please post the error message?
    BTW:
              queueNext = (queueNext + 1);
              queueEntries ++;These two statements are equivalent, yet use different syntax.
    Another hint:
    http://java.sun.com/docs/codeconv/

  • How does flatten to string work with arrays?

    Hi all,
    I'm currently trying to get my head around how flatten to string works in terms of using it to write a configuration file which is loaded on startup in my VI. Writing and loading the configuration file is no problem and it is working beautifully. However... this is for a data acquisition system and the configuration file stores all the calibration data in the system which is entered through arrays. Anyway, the data recorded by my VI is to be post processed using MATLAB and needs to apply the calibration data stored in the configuration file.
    So I've been trying to work out how to get MATLAB to decypher the configuration file, but... I can't make heads or tails as to how the data is written into the file. I made a mock up of the saving file routine as you can see below, and run it a number of times by changing the input array dimensions and the values.
    Then opened the saved file to see if I can find a pattern... but I can't! Simply changing the element values changes the number of "\   \'s" Here is what I produced from my trials:
    [1x1 0]
    Config=\00\00\00\01\00\00\00\00\00\00\00\00      (1x1 array of 0's)
    [1x1 1]
    Config=\00\00\00\01?ð\00\00\00\00\00\00            (1x1 array of 1's)
    [1x1 2]
    Config=\00\00\00\01@\00\00\00\00\00\00\00       (1x1 array of 2's)
    [1x2 0]
    Config=\00\00\00\02\00\00\00\00\00\00\00\00\00\00\​00\00\00\00\00\00      (1x2 array of 0's)
    [1x2 1]
    Config=\00\00\00\02?ð\00\00\00\00\00\00?ð\00\00\00​\00\00\00                  (1x2 array of 1's)
    [1x2 2]
    Config=\00\00\00\02?ð\00\00\00\00\00\00?ð\00\00\00​\00\00\00                  (1x2 array of 2's) etc. etc. etc
    [2x2 0]
    Config=\00\00\00\02\00\00\00\02\00\00\00\00\00\00\​00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00​\00\00\00\00\00\00\00\00\00     
    [2x2 1]
    Config=\00\00\00\02\00\00\00\02?ð\00\00\00\00\00\0​0?ð\00\00\00\00\00\00?ð\00\00\00\00\00\00?ð\00\00\​00\00\00\00
    [2x2 2]
    Config=\00\00\00\02\00\00\00\02@\00\00\00\00\00\00​\00@\00\00\00\00\00\00\00@\00\00\00\00\00\00\00@\0​0\00\00\00\00\00\00
    Could someone explain to me how flatten to string flattens the array information? Particularly when the array elements are double precision? I look forward to any help that anyone can offer!
    Thanks,
    Stirling
    Message Edited by stirlsilver on 09-08-2007 08:47 AM
    Attachments:
    saveconfig.png ‏7 KB

    There are optional inputs to "flatten to string" That you can use to modify the outcome as needed. For example you can do little endian.
    You can also omit the array size from the flattened data (definitely not recommended for 2D arrays).
    LabVIEW Champion . Do more with less code and in less time .

  • Empty string in an array :(

    Hi, im new here and stupid :D
    I have an assignment to do and im really stuck on this bit. I have 2 arrays, 1 of heights and 1 of towns -
    private int[] spotHeights = { 100,  // At 0 km
    120,120,150,120,200,200,210,220,230,240, // Heights at 1-10 km
    300,300,300,250,250,200,150,150,150,130, // Heights at 11-20 km
    120,120,150,120,200,200,210,220,230,240, // Heights at 21-30 km
    300,300,300,250,250,200,150,150,150,130, // Heights at 31-40 km
    120,120,150,120,200,200,210,220,230,240 }; // Heights at 41-50 km
    private String[] towns = { "Berwick",  // At 0 km
    "","Edinburgh","","","","Falkirk","","","","", // Towns at 1-10 km
    "","","","","","Stirling","","","","", // Towns at 11-20 km
    "","Doune","","","","","","Dunblane","","", // Towns at 21-30 km
    "","","","Ashfield","","","","Kinbuck","","", // Towns at 31-40 km
    "","","Perth","","","","","","","Aviemore" }; // Towns at 41-50 km
    What i have to do is draw a dot where there is a town on a sort of map thing. Only thing is i dont know how to check whether there is something in the array or not... I hope you understand what im asking and u can help me :D That would be great.
    Thanks
    Awe

    ok, in the second array, theres lots of "" and that means theres nothing in that part of the array. Well i need to know how to find out whether there is something in the arrays or not :/ hard to explain... i think its something like variable.equals[""] but that never works, maybe im doing it wrong.

  • How to delete string from an array

    I just want to know that what changes i can do to delete the string if contains any extra characters like digits and punctuation marks in the middle or begining of the string but not at the end of the string, i've already tried to delete only the punctuation marks at the end of the string and keep that word. Please dont forget that i m a beginer
    import java.io.*;
    import java.util.*;
    class Project
    public static void main()throws IOException
    // set up input stream
    File finput = new File("C:\\f1.txt");
    FileReader fr = new FileReader(finput);
    BufferedReader fin = new BufferedReader (fr);
    // set up output stream
    File foutput = new File("C:\\f3.txt");
    FileWriter fw = new FileWriter (foutput);
    PrintWriter fout = new PrintWriter (fw);
    String nextLine; // a line read from the file
    StringTokenizer t; // the words within the line
    ArrayList words = new ArrayList(); // an array of words
    //String n = {0,1,2,3,4,5,6,7,8,9};
    System.out.println("Reading file.\n");
    // start
    while (true)
    nextLine =fin.readLine(); // read from input file
    if (nextLine==null) break; // if no more lines, get out
    t = new StringTokenizer(nextLine); // identify words
    while (t.hasMoreTokens())
    String str = (String)t.nextToken();
    str = str.toLowerCase(); // Converting all uppercase to lowercase.
    // Replacing all punctuation marks.
    str=str.replace(',',' ');
    str=str.replace('?',' ');
    str=str.replace('!',' ');
    str=str.replace('.',' ');
    str=str.replace(':',' ');
    str=str.replace(';',' ');
    str=str.replace('"',' ');
    str=str.replace('"',' ');
    str=str.trim(); // Removing empty spaces after words
    words.add(str); // add them to array
    String z; // Declaring string z for sorting.
    for (int i=0; i<words.size(); i++)
    for (int j=i+1; j<words.size(); j++)
    // Sorting the Array list.
    if (((String)words.get(j)).compareTo((String)words.get(i))<0)
    z=(String)words.get(i);
    words.remove(i);
    words.add(i,(String)words.get(j-1));
    words.remove(j);
    words.add(j,z);
    // To replacing word which have got "'".
    if ((String)words.get(i)).indexOf("'")!=-1)
    a="";
    int count[]=new int[words.size()]; //Creating int array for counting the repetition.
    for (int i=0;i<=words.size()-1;i++)
    for (int j=i+1;j<=words.size()-1;j++)
    //Counting the repetition of the string.
    //if (((String)words.get(j)).compareTo((String)words.get(i))==0)
    if (((String)words.get(j)).equals((String)words.get(i))==true)
    count[i]++;
    words.remove(j);
    j=j-1;
    System.out.println("Dictionary\t|\tRepetition");
    System.out.println("==========\t \t==========\n");
    for (int i=0; i<words.size(); i++)
    count[i]++; // initialinzing the value with 1
    // Printing result on the output file.
    fout.println((String)words.get(i));
    // Printing result on the screen with histogram.
    System.out.println((String)words.get(i)+ "\t\t|\t" +count[i]);
    fout.close();
    System.out.println();
    System.out.println("Finished");
    } //end of main.

    The code that you pasted does not seem like written by a beginner. So, did you write the code?
    If so, you should have no problem solving this simple thing.
    If not, then copy and pasting a block of program that you don't understand will keep you as a beginner all the time, so can't help you if you are willing to stay at beginner.
    --lichu                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Convert a string of an array to an int

    I want to convert numbers[k] which is a string array to an int. How can i do this. I have tried everyting on the net I can find but not much help

    This is my code and I still get a complier error of found: String
    required:int
    public void squares()
    {System.out.println(stringNumbers.length);
    for (int k=3;k<=4;k++)
    {   System.out.println("the value of k is "+k);
         sqCount++;
    //int sqsize= (Integer) stringNumbers[k].valueOf(sqsize);
    for (int p=0;p<=stringNumbers.length;p++)
    {  String str=stringNumbers[p];
              Integer.parseInt(str);
    for(int i=0;i<=4;i++)
    {   xcord=i;
         for(int j=0;j<=4;j++)
    {   ycord=j;
         if(xcord+stringNumbers[k]<=stringNumbers[2]&& ycord+stringNumbers[k]<=stringNumbers[2])
         { //creating an array for each set of sqNum,xcord,ycord
         System.out.println(sqCount+" "+xcord+" "+ycord);
         else
         { System.out.print("");
    }

  • Is there an easy way to convert a long string into an array?

    I can convert a long string into a 1-d array by parsing and using build array, but I would like to know if there is a function to make this easier.
    For example:
    from/   aaaaaaaabbbbbbbbccccccccdddddddd         (string of ascii)
    to/       an array that is 1-d with each element having eight characters
              aaaaaaaa
              bbbbbbbb
              cccccccc
              dddddddd
    Thank you.
    Solved!
    Go to Solution.

    Try something like this:
    (If you can guarantee that the string length is an integer multiple of 8, you an drop the two triangular modes in the upper left. )
    Message Edited by altenbach on 03-14-2010 06:40 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    ChopString.png ‏9 KB

Maybe you are looking for

  • How do I add US holidays to my iCal?

    How do I add US holidays to my iCal?

  • What's Wrong with the Artwork Feature?

    I used to have all my files saved with artwork, but lately, I've been having files lose their artwork and some files don't seem to save artwork no matter how I put it in (either through right click and paste or info). There's nothing wrong with the f

  • Very Large Numbers Question

    I am a student with a question about how Java handles very large numbers. Regarding this from our teacher: "...the program produces values that are larger than Java can represent and the obvious way to test their size does not work. That means that a

  • How to loop through a KM Folder ?

    Hi ....can someone please let me know how  to loop through a KM Folder having many documents , files etc . Waiting for replies !! Regards Smita

  • After burning idvd the intro is pixelating.

    The Chapters and video all play correctly, but the intro does not. What is happening? Thanks