Click here to Skip to main content
15,922,584 members
Please Sign up or sign in to vote.
2.50/5 (3 votes)
See more:
Hi Sir/Madam

I have a doubt about string in C#
Let Say a String array a[] have values 0,1,2
now i need to convert this string array to string(ie let say string s=012)

How can i acheive this...I am very new to C# and please Help me..
Thanks inadvance
Posted
Comments
Shine Ashraf 2-Jul-13 6:56am    
use foreach loop and fetch and merge each string item from array.
Thanks7872 2-Jul-13 7:07am    
a[0]+a[1]+a[2]...?
Sergey Alexandrovich Kryukov 3-Aug-13 0:41am    
Really bad idea. Even if you do it in a loop... As string is immutable, it's really bad for performance.
—SA

Try this,,,,:)


C#
string[] ids = { "2343", "2344", "2345" };
      string idString = String.Join(",", ids);
      Response.Write(idString);
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 3-Aug-13 0:43am    
Amazingly, this answer is the only acceptable one so far. Other did not realize that strings are immutable, so concatenation is bad for performance. My 5.
—SA
Hi,
you can try this:

C#
string[] _str = new string[]{"a","b","c"};
           string val = string.Concat(_str);
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 3-Aug-13 0:44am    
Really, really bad solution. It will work, but you are missing that strings are immutable, so loop with concatenation will be bad for performance. The only valid solution so far it the Solution 5.
—SA
See this link for all string manipulation functions
http://www.blackwasp.co.uk/SimpleStringManipulation.aspx[^]
 
Share this answer
 
C#
String[] a = {"1","2","3"};
String result = "";
int i = 0;
while(i< a.Length)
{
result = result + a[i];
i++;
}
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 3-Aug-13 0:45am    
Really, really bad solution. It will work, but you are missing that strings are immutable, so loop with concatenation will be bad for performance. The only valid solution so far it the Solution 5.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900