Click here to Skip to main content
15,920,614 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all

Below is the code where i am getting elements in array

HTML
$a=@($Split_ResultOfMasterListUser)

$a | Sort-Object | Get-Unique


below is the sample output in powershell console

root
sh506pa
snapp
sshd
su004sa
sys
tr005ma
trnadm
uucp
ve001na
vendabe
we002za
webm
webmd
wipftp
zapftp


now i want to assign these values to a string joining by comma(,)

e.g.
,nex3mzn,nex3slw,nex3orp,nex87vj,nex7uxw,nex7geg,nex7lmw,nex3hxf,nex8fas,root,bin,root,bin,sys,bin,adm,nuucp,uucp,


Please tell me how to do this.
Posted

// Assign array to string //

string[] array = new string[$a];

// Split array //
array[0]="root";
array[1]="snapp";
like this ......
// Call the methods.////
//
string result1 = ConvertStringArrayToString(array);
// Display the results.
//
Console.WriteLine(result1);
C#
static string ConvertStringArrayToString(string[] array)
   {
   //
   // Concatenate all the elements into a StringBuilder.
   //
   StringBuilder builder = new StringBuilder();
   foreach (string value in array)
   {
       builder.Append(value);
       builder.Append(',');
   }
   return builder.ToString();
   }


 Since i am new to c# hope this help full....
 
Share this answer
 
You should have a look at about_Join[^].

Good work :)
 
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