Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert array of ints into string?

Status
Not open for further replies.

MattWoberts

Programmer
Oct 12, 2001
156
GB
Hi,

In VB and most other languages, there are functions that take an array amd return a string representation of it, using whatever you supply as a delimiter.

I can't find the equivilent in c# - is there anything?

I have an array of ints, and I want to get them into a string of format "1,3,4,5"

I can do this by looping through the array in code, but surely theres an easier way?
 
Try string.Join. Of course, the input is an array of strings so you have to cope with converting your int[] into a string[]. Altogether it might look something like this:

Code:
int[] intMyArray;
string[] strTemp = new string[intMyArray.Length];
string strCommaDelimited;

//Can't remember the exact parameters to the CopyTo method
intMyArray.CopyTo(strTemp);
strCommaDelimited = string.Join(",", strTemp);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top