convert int array to string string

Source: Internet
Author: User
Tags array to string

Flattening a numeric array into a string, using loops all the time, the code is simple, but always wants to be more concise, refactoring

int[] Intarray =New int[] {1,2,3,4,5 };stringresult =string. Empty; for(inti =0; i < intarray.length; i++){    if(!string. IsNullOrEmpty (Result)) result+=","+Intarray[i]; Elseresult=Intarray[i]. ToString ();}

Today only know that there are really small tricks, simple cute!

int array goes to a delimited string

int 1 2 3  }; string [] STRs = array.convertall<intstringdelegate(intreturn  Input. ToString ();}); string string. Join ("; ", STRs);

int array to string[] array also does not require write loops

int [] ints={1,2,3,4== (string[]) List.toarray (new String[ints.length]);
int 1 2 3  }; string [] output = array.convertall<intstring> (ints, i = i.tostring ());

convert int array to string string

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.