Click here to Skip to main content
15,899,634 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I would like to add two string variables to a double string array:

C#
string a = "foo1";
string b = "foo2";
string[] c = new string[10];
c = ?????(a,b);


Then how do you separate a double string array to two single string variables:

d = ???(c);
e = ???(c);
Posted
Updated 19-Jan-16 2:29am
v4
Comments
deepankarbhatnagar 19-Jan-16 6:59am    
Is your string is comma separated?
deepankarbhatnagar 19-Jan-16 6:59am    
Is your string is comma separated
Sri Nivas (Vasu) 19-Jan-16 9:39am    
Do you mean
"double string array" is "array with size 2" ?

Easiest way: pick a character that can't be in eitehr string:
C#
string a = "foo1";
string b = "foo2";
string combined = string.Join("|", a, b);

To separate them again, just use Split:
C#
string[] parts = combined.Split('|');
string a = parts[0];
string b = parts[1];

But if you are doing this to store the information in a file or database, there are probably better things you can do instead of messing with string concatenation at all!
 
Share this answer
 
It is not clear what exactly do you want to achieve, but some samples...
C#
string[] arr = new string[] {"stringA", "stringB"};
string A = arr[0];
string B = arr[1];
string[] arr1 = new string[] {A, B};
 
Share this answer
 

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