Converting String Array -- String

Hi All,
I am converting String array to string using the following code:
String[] a= ....;
StringBuffer result = new StringBuffer();
if (a.length > 0) {
result.append(a[0]);
for (int i=1; i<a.length; i++) {
result.append(a);
return result.toString();
Is there is any other easy or efficient way to convert rather than the above code ?
Thanks,
J.Kathir

It could have been written:
StringBuffer result = new StringBuffer();
for(int i=0; i<a.length; ++ i)
    result.append(a);
return result.toString();
Or in 1.5 lingo
StringBuilder result = new StringBuilder(); //slightly less overhead
for(String s : a)
    result.append(s);
return result.toString();If you aren't picky about the format of the resulting string,
you could use the java.utilArrays method )]toString(Object[]):
String[] array= {"Hello", "World", "this", "is", "a", "1.5", "method"};
String s = Arrays.toString(array); //[Hello, World, this, is, a, 1.5, method]

Similar Messages

  • Problem converting U8 array to date-time string

    Hi All,
    How can I convert U8 array (time_t data type from C dll) to date time string?
    A dll function that I am calling has a structure of string, integer and time_t as one of the parameters. Instead of passing cluster, I pass an array of U8 of the size that the structure should be. All the members of the strcuture and parsed correctly except the date/time.
    Function Parameter:
    typedef struct {
    Int AlarmState ;
    Int AlarmGrade ;
    TCHAR AlarmMessage [100] ;
    time_t AlarmTimeStamp ;
    } WV_ALARM_INFO ;
    Total size = 4 + 4 + 100 + 4 = 112
    Using Call Library Function, I set the parameter type to Array of U8 and size 112.
    After the array is populated when the function is called, I have done the following to interpret date and time.
    1) Using Extract Zero Terminated String.VI I converted U8 array (of size 4) to string.
    2) Type casted string to integer (I32).
    3) Swap bytes
    4) Swap Words
    5) Format Date/Time String.
    Please see the attached screenshot for visual display of the above.
    Ideas on why the year is incorrect?
    Mimansa
    Attachments:
    Time.JPG ‏102 KB

    Hi Mimansa,
    Is it only the year that is incorrect? Also, where did you find that ABC\0 VI that you use 3 times? Did you make it or is it in a labview library somewhere?
    Thanks,
    Laura

  • Convert an array of strings into a single string

    Hi
    I am having trouble trying to figure out how to convert an array of strings into a single string.
    I am taking serial data via serial read in a loop to improve data transfer.  This means I am taking the data in chunks and these chunks are being dumped into an array.  However I want to combine all elements in the array into a single string (should be easy but I can't seem to make it work).
    In addition to this I would also like to then split the string by the comma separator so if any advice could be given on this it would be much appreciated.
    Many Thanks
    Ashley.

    Well, you don't even need to create the intermediary string array, right? This does exactly the same as CCs attachment:
    Back to your serial code:
    Why don't you built the array at the loop boundary? Same result.
    You could even built the string directly as shown here.
    Message Edited by altenbach on 12-20-2005 09:39 AM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    autoindexing.png ‏5 KB
    concatenate.png ‏5 KB
    StringToU32Array.png ‏3 KB

  • How to convert 1D array of string to string

    How to convert 1D array of string to string.

    Maximus00, as Pavel indicated, there is a lesser known feature of "Concatenate Strings" that does exactly what your code is doing if the input is an array of strings. In one step! See attached image.
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    ConcatenateArray ofStrings.gif ‏7 KB

  • 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!
    ~

  • Converting strings to the floating number and plotting

    Hello,
    I have a question regardting converting string of numbers to the floating bumbers and plot for voltage vs. weight.
    The load cell for the ADC resolution is 16 bits, and the voltage will be in between +-5 volts.
    The problem, I have the most is converting the string of numbers to the floating numbers, in my case is the weight.
    Attachments:
    tunnelv1.vi ‏139 KB

    When you say "string of numbers" do you mean an array? What is the specific issue you are having? You seem to have orange wires running all over the place. Give a small example demonstrating the problem.
    Mike...
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps

  • Converting String type to inte type

    Can any one tell me how I can convert an array of Strings into an array of integers??

    it's simple ..... it's like this...
       // some code goes here....
       String num[]={"23", "342", "21", "1"};
        int n[]= new int[num.length];
        for(int i=0; i<num.length; i++)
             n=Integer.parseInt(num[i]); // << -- convert string to int then copied it to int[]
    // rest of your code....

  • Convert String from ASCII to ANSI

    Hi,
    a command line instruction via LabVIEW function "System Exec.vi" retrieves me a string in ASCII format. Is there a function to convert string from ASCII to ANSII format? I use LabVIEW 8.5 German Installation.
    Kind Regards
    Christian
    Test Engineering
    digades GmbH
    www.digades.com

    Hallo Christian,
    AFAIK there is no such in function in LabView...
    But you can:
    - use "Search and replace string" to search for ASCII chars and replace them by their corresponding ANSI char, do this in a loop for all chars to be replaced (acceptable speed for small strings...)
    - convert the string to an U8 array and use a lookup table to convert all bytes from ASCII to ANSI, convert back to string (may be faster for long strings...)
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • Not able to convert string attribute to number and date please help me out

    not able to convert string attribute to number and date attribute. While using string to date conversion it shows result as failure.As I am reading from a text file. please help me out

    Hi,
    You need to provide an example value that's failing and the date formats in the reference data you're using. It's more than likely you don't have the correct format in your ref data.
    regards,
    Nick

  • Convert String to Date and Format the Date Expression in SSRS

    Hi,
    I have a parameter used to select a month and year  string that looks like:    jun-2013
    I can convert it to a date, but what I want to do is,  when a user selects a particular month-year  (let's say "jun-2013")
    I  populate one text box with the date the user selected , and (the challenge Im having is)  I want to populate a text box next to the first text box with the month-year  2 months ahead.    So if the user selects 
    jun-2013   textbox A will show  jun-2013 
    and textbox B will show  aug-2013..
    I have tried:
    =Format(Format(CDate(Parameters!month.Value  ),  
    "MM-YYYY"  )+ 2  )   -- But this gives an error
    This returns the month in number format   like "8"    for august...
    =Format(Format(CDate(Parameters!month.Value  ), 
    "MM"  )+ 2  )
    What is the proper syntax to give me the result    in this format =  "aug-2013"  ???
    Thanks in advance.
    MC
    M Collier

    You can convert a string that represents a date to a date object using the util.scand JavaScript method, and then format a date object to a string representation using the util.printd method. For more information, see:
    http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.1254.html
    http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.1251.html
    In your case, the code would be something like:
    var sDate = "2013-01-10";
    // Convert string to date
    var oDate = util.scand("yyyy-mm-dd", sDate);
    // Convert date to new string
    var sDate2 = util.printd("mm/dd/yyyy", oDate);
    // Set a field value
    getField("date2").value = sDate2;
    The exact code you'd use depends on where you place the script and where you're getting the original date string, but this should get you started.

  • Convert String variable value  to an Object referece type

    Hi all,
    I want to know that if there any possible way to convert String variable value to a Object reference type in java. I'll explain by example if this is not clear.
    Let's think that there is a string variable name like,
    String name="HelloWorld";
    and there is a class name same to the variable value.
    class HelloWorld
    I am passing this string variable value to a method which is going to make a object of helloworld;
    new convertobj().convert("HelloWorld");
    class convertobj{
    public void convert(String name){
    // in hert it is going to create the object of HelloWorld;
    // HelloWorld hello=new HelloWorld(); just like this.
    now i want to do this from the name variable value.( name na=new name()) like wise.
    please let me know if there any possible way to do that.
    I am just passing the name of class by string variable then i wanted to make a instance of the class which come through the variable value.
    thanx.

    Either cast the object to a HelloWorld or use the reflection API (Google it) - with the reflection API you can discover what methods are available.
    Note: if you are planning to pass in various string arguments and instantiate a class which you expect to have a certain method... you should define an interface and have all of your classes that you will call in this way implement the interface (that way you're sure the class has a method of that name). You can then just cast the object to the interface type and call the method.
    John

  • How to convert string to an integer in SQL Server 2008

    Hi All,
    How to convert string to an integer in sql server,
    Input : string str="1,2,3,5"
    Output would be : 1,2,3,5
    Thanks in advance.
    Regards,
    Sunil

    No, you cannot convert to INT and get 1,2,3 BUT you can get
    1
    2
    3
    Is it ok?
    CREATE FUNCTION [dbo].[SplitString]
             @str VARCHAR(MAX)
        RETURNS @ret TABLE (token VARCHAR(MAX))
         AS
         BEGIN
        DECLARE @x XML 
        SET @x = '<t>' + REPLACE(@str, ',', '</t><t>') + '</t>'
        INSERT INTO @ret
            SELECT x.i.value('.', 'VARCHAR(MAX)') AS token
            FROM @x.nodes('//t') x(i)
        RETURN
       END
    ----Usage
    SELECT * FROM SplitString ('1,2,3')
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • How to convert String (dd-MMM-yyyy) to oracle.jbo.domain.Date

    Hi
    Could you please tell how do I convert String of date in format dd-MM-yyyy to ADF date? Please show me some sample.
    Thanks

    http://javaalmanac.com/egs/java.text/FormatDateDef.html
    Once you have a java.util.Date you can convert it to oracle.jbo.domain.Date. (see http://www.fifkredit.com/bc4jdoc/rt/oracle/jbo/domain/Date.html)

  • Facing problem in converting string to date using getOANLSServices()

    I am trying to set a value for date field in my vo and trying to insert into the table.
    In controller I am getting the String which has a date:
    ex: String date="01-NOV-2007";
    while setting into the row I need to convert into Date but it is returning null.
    The below code I used
    to convert into date :
    Date dt = new Date(getOADBTransaction().getOANLSServices().stringToDate(date));
    But this dt is returning a null value is there any solution please advise me.
    Regards!
    Smarajeet

    Smarajeet ,
    See this thread, in one of my replies i have mentioned how to convert string to java.sql.date.You can use the same for oracle.jbo.domain.Date.
    urgent!How to set the default selected date for an OAMessageDateFieldBean
    --Mukul                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Converting String To XML Format and send as attachment

    Hi
    My requirement is to convert String into XML Format and that XML File i have to send as an attachment
    can any one one give solution for this Problem.
    Thank you
    Venkatesh.K

    hi,
    i m filling the itab first and converting to xml
    itab contaning these data
    GS_PERSON-CUST_ID   = '3'.
    GS_PERSON-FIRSTNAME = 'Bill'.
    GS_PERSON-LASTNAME  = 'Gates'.
    APPEND GS_PERSON TO GT_PERSON.
    GS_PERSON-CUST_ID   = '4'.
    GS_PERSON-FIRSTNAME = 'Frodo'.
    GS_PERSON-LASTNAME  = 'Baggins'.
    APPEND GS_PERSON TO GT_PERSON.
    after conversion data is coming like that
    #<?xml version="1.0" encoding="utf-16"?>
    <CUSTOMERS>
      <item>
        <customer_id>0003</customer_id>
        <first_name>Bill</first_name>
        <last_name>Gates</last_name>
      </item>
      <item>
        <customer_id>0004</customer_id>
        <first_name>Frodo</first_name>
        <last_name>Baggins</last_name>
      </item>
    </CUSTOMERS>
    but errors are  1) # is coming at the first
                            2)for 'encoding="utf-16"?>', it is not coming perfectly, some other data (iso-8859-1) should come here
    can anybody plz solve it.
    regards,
    viki

Maybe you are looking for

  • How do I make the search bar on the default Firefox Homepage search in Google rather than AOL?

    On the default home page for Firefox 4, the one with the restore previous session on it, the search bar links to AOL Search. This does not seem to happen on other computers. How do I make it search in Google?

  • Updating smart playlists

    I have set up a smart playlist, which says not to play songs played in the last 7 days, and limits the playlist to 700 songs so that the playlist will always fit on my 4gb nano. When I've plugged it in over the last couple of days, it says "cannot up

  • FocusListener not working

    hello everybody, class MyPanel extends JPanel implements FocusListener    public MyPanel(String str)       // some gui code of this class (ignored for brevity)       dialog = new JDialog();       dialog.getContentPane().add(this);       dialog.setSiz

  • Caller ID block

    how can I delete the caller ID when text messaging with Samsung SIII?

  • Purchase from the Apple Store

    I bought the album Glad Rag Doll from the Apple store, and it showed up in Purchases on the left side of iTunes, and my credit card was charged. However, it did not show up in my Music list, and when I Search for it, it does not appear. It must be in