Convert a string to an array/collection

Hi,
I have a string
String s = "[ab,cd,ef,gh]";How can I convert this into a string array , arraylist or vector such that ab, cd, ef, gh are the elements of the array/collection.
Please help.
Any help in this regard will be well appreciated with dukes.
Regards,
Anees

virusakos wrote:
codingMonkey, the "^\\[|\\]$" regular expression will only work for [....,...,....] inputs and not for [...,[....],]...[,...] inputs.
The OP should find the correct regular expression according to the requirements ;-)Meaning that any brackets which are part of the actual data will remain intact.

Similar Messages

  • 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.

  • I want to convert a String into an array of bytes

    I am working with telnet programming with java, where I want to convert login name and password of an online user in 'String' format to 'Bytes', plz help me. Which Input or Output Stream I can use

    Assuming you've got the username / password into a String object, you can convert it to a byte[] array using this method.
    String.getBytes();
    Look at the String API
    http://java.sun.com/j2se/1.3/docs/api/java/lang/String.html
    Hope that helps.

  • How to convert a String to an array

    Can somebody tell me how to convert a String to an array

    ronisto wrote:
    Can somebody tell me how to convert a String to an arrayI assume you mean to convert it into an array of the individual characters that comprise the String.
    Can you not simply look at the API documentation? Nothing in the String API jumps out at you?
    http://java.sun.com/javase/6/docs/api/index.html

  • 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

  • Convert a string to an array of character

    What would be the easiest way to convert a string "HELLO" to an array of character "H" "E" "L" "L" "O" ?
    I have a way to do it with a for loop but I'm wondering if there is nothing even more simple.
    Thanks in advance,
    Martin

    Try typecast instead.
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    HELLOCast.gif ‏2 KB

  • 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.

  • 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("");
    }

  • Convert binary string into binary array

    Dear I am looking for a way to convert my ten bit string array into 10 bit array.
    Any idea?

    Yes, but you need to tell us in more details what you have and what you want.
    There is no "10bit string", they come in integer multiples of 8 bits. Some possible interpretations:
    Maybe you have a 2 character string (16bits). Do you want the 10 low order bits?
    Maybe you have a 10 character formatted string of zeroes and ones, one character for each bit.
    Do you have a long string and every 10 consecutive bits are one 10bit number that you want as integer?
    Please clarify!
    There is no "10bit array". Do you want:
    a boolean array with 10 elements, one element per bit?
    An integer array if ones and zeroes?
    An array of U16, each element corresponding to 10bits of the original string?
    something else?
    It might help if you could attach a small example containing typical data. (make current values default before saving and attaching here).
    LabVIEW Champion . Do more with less code and in less time .

  • Convert HEX String into HEX Array

    Hi!
    Probably a silly question, but I am looking for a way to convert a ROM ID number such as "5E03C21000BA" into an short hexadecimal array.
    The way to do this in C would probably be
    char[17] str_romID = "5E03C21000BA";
    uchar[8] romID;
    sscanf(str_romID, "%02X%02X%02X%02X%02X%02X%02X%02X",
    &romID[0], &romID[1], &romID[2], &romID[3],
    &romID[4], &romID[5], &romID[6], &romID[7]);
    but I can't seem to find a way to do this in LabVIEW. I would be very grateful if you could help me out with a sample program. Thanks ever so much!
    Stefan

    Hello Blondchen,
    I have attached a picture to my last explanation. This example doesn't take care of strings with an uneven number of chars!
    My array has only 6 numbers as you only gave a string with 12 chars... That's what I asked before: how should we know where to split your string to the single numbers? Normally I would take 2 chars to form a byte (as I did in the example). If you give me 16 chars I give you 8 bytes...
    I also think your C byte array will be an U8 array in LabView. If you REALLY need I8 numbers you can change the default type of the "hex to string" or cast to I8 (advanced->data manipulation->type cast) after the conversion.
    Best regards,
    GerdW
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome
    Attachments:
    ConvertHexHex.png ‏13 KB

  • Is it possible to convert from string to variant?

    Hi!
    I would like to convert a text string to variant. I'm doing this because I would like to merge a couple of signals and then save all the signals in a lvm-file. Could someone please explain how to convert from text to variant, is it possible?
    Thanks in advance!
    Regards,
    Mattias
    Attachments:
    Merge signals.JPG ‏27 KB

    What you are attempting to do is possible, but might not give you the results you expect.  All you need to do is convert your string to an array of U8s using the String to Byte Array conversion primitive.  In the file, you will get a single character per line of the file expressed as the ASCII code.  When you read it, convert to U8s, then use Byte Array to String to get your string back.
    You may also want to read up on LVM files.  There are several places to put strings that work a little better than this.
    This account is no longer active. Contact ShadesOfGray for current posts and information.

  • How to convert an array collection instance to a complex object for interaction with webservice

    Hi there,
    I have a stubborn problem that I am trying to work out the best way to solve the problem.  I am interacting with a WebService via HTTPService calling a method called find(String name) and this returns me a List of ComplexObjects that contain general string and int params and also lists of other Complex Objects.  Now using the code:
    ArrayCollection newOriginalResultsArray = new ArrayCollection(event.result as Array)
    flex converts my complex objects results to an arraycollection so that I can use it in datagrids etc.  Now up until this part is all good.  My problem is when getting a single instance from the results list, updating it by moving data around in a new datagrid for example - I want to interact with the webservice again to do an create/update.  This is where I am having problems - because these webservice methods require the complex object as a parameter - I am struggling to understand how I can convert the array collection instance back to my complex object without iterating over it and casting it back (maybe this is the only way - but I am hoping not).
    I am hoping that there is a simple solution that I am missing and that there is some smart cookie out there that could provide me with an answer - or at least somewhere to start looking. I guess if I have no other alternative - maybe I need to get the people who built the service to change it to accept an array - and let them do the conversion.
    Any help would be greatly appreciated.
    Bert

    Hi Bert,
    According to my knowledge you can use describeType(Object) method which will return an XML... That XML will contain Properties and values just iterate through the XML and create a new Object..   Probably u can use this method...
    public function getObject(reqObj:Object,obj:Object,instanceName:String,name:String=null,index:int=-1):Obj ect
                if(!reqObj)
                    reqObj = new Object();
                var classInfo:XML = describeType(obj);
                var className:String = instanceName;
                if(name!=null)
                    className=name+"."+className;
                if(index!=-1)
                    className=className+"["+index+"]";
                for each (var v:XML in classInfo..accessor)
                    var attributeName:String=v.@name;
                    var value:* = obj[attributeName]
                    var type:String = v.@type;
                    if(!value)
                        reqObj[className+"."+attributeName] = value; 
                    else if(type == "mx.collections::ArrayCollection")
                        for(var i:int=0;i<value.length;i++)
                            var temp:Object=value.getItemAt(i);
                            getReqObject(reqObj,temp,attributeName,className,i);
                    else if(type == "String" || type == "Number" || type == "int" || type == "Boolean")
                        reqObj[ className+"."+attributeName] = value; 
                    else if (type == "Object")
                        for (var p:String in value)
                            reqObj[ className+"."+attributeName+"."+p] = value[p];
                    else
                        getReqObject(reqObj,value,attributeName,className);
                return reqObj;
    Thanks,
    Pradeep

  • Need help in converting string to numeric array

    I am trying to convert a string to a numeric array ... the first # in the string gets cut off, the last three seem to come through. 
    This may be fairly simple, but I really haven't worked with the string functions all that much.
    Help would be appreciated.
    Thanks,
    Attachments:
    String to Array Example.vi ‏10 KB

    Steve Chandler wrote:
    If you remove the first and last byte from the string using string subset then the read spreadsheet string would probably have worked.
    Yup.
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    String to Array ExampleMOD2.vi ‏10 KB

  • How to convert a string data to a 1 d array

    Dear All,
    I am wondering if somebody help me.
    In the attached fle i have my program (in labview 8.6) which read temperature data and updates temperature during the time.
    I want to use the updated temperature in a calculation.  How can i get the new temperature which i think is in a string format and convert it to 1 d array?
    I tried but the number that i got from temperature was not the same temperature which is shonw in data section of the program.
    Could somebody please help me?
    Regards, 
    Solved!
    Go to Solution.
    Attachments:
    Readfiles[1].vi ‏152 KB

    You are not reading temperature, you are reading a binary file. You seem to be assuming string format but do you really know? No one here can tell since you did not attach the file If it is you would need to use one of the string conversion functions. And please, get rid of the Data local variable. You are already usin shift registers. Do the same with the data from the file.

  • How to convert a string into a collection of KeyEvents

    I'm working on a program that must interact with a 3rd party application (closed to me, I have no access to the code or anything like that). I have been unable to send data to the program by getting its OutputStream. The only thing that has worked was using a Robot object to send individual key events (i.e. robot.keyPress(KeyEvent.VK_A);). Therefore I'm looking to convert a string (many different strings actually) into a collection of their associated KeyEvents so I can send them to the other application. Does anyone know a good way of doing it, or is anyone able to help me with using the OutputStream?
    Thank you!
    (The 3rd party application is Attachmate InfoConnect, a Unisys terminal emulation program that I have to use to access a mainframe).

    Here is a code sample.     public void checknumber(int vsize){
    int total;
    String anum;
    anum = tf2.getText();
    validnumber = true;
    lines2combine = 1;     //default (an integer)
    recs2make = 1;          //default
    try{
    lines2combine = Integer.parseInt(anum);
    catch (NumberFormatException e){
              System.out.println("Entry for lines to combine not numeric");
         validnumber = false;
         d1Title = "Data Entry Error";
         d1Txt = "For number for lines to combine;";
         d2Txt = "Enter a number.";
         doMessage();

Maybe you are looking for