Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

How do i convert the contents of an array to a string. (see below)

 

Array

1

2

3

4

5

 

To string

 

"1,2,3,4,5"

 

The array could be bigger than 5

phillip Restall
Posted

One of I'm sure many ways!

 

Dim myArray() As Integer = {1, 2, 3, 4, 5}
Dim myStrinbuilder As New StringBuilder
Dim myString As String

For counter As Integer = 0 To myArray.GetUpperBound(0)
   
      myStrinbuilder.Append(myArray(counter))
      myStrinbuilder.Append(",")

Next
myString = myStrinbuilder.ToString

Posted

//C#

int[] myIntArray = new int[5] { 1, 2, 3, 4, 5 };

Array myArray= myIntArray;

string str="";

foreach(int i in myArray)

{

str += i.ToString()+",";

}

Console.WriteLine( str);

 

Assuming that you wanted to make use of the Array Class

otherwise use the myIntArray in the foreach loop

foreach(int i in myIntArray )
Posted
Assuming that you wanted to make use of the Array Class

otherwise use the myIntArray in the foreach loop

 

Thanks Guys, I'll give it a try

phillip Restall

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...