Monday, January 21, 2013

[Using list ForEach] Convert list values to string, appending with delimiter



Using Linq  we can convert list values to string appending with delimiter. Here it is appended with '|' (pipe)


Code snippet:

Example:1

            string strData = "World is Mine";
            string[] split = strData.Split(' ');

            //logic work done on split values.
            //  .
            //  .
            //  .
            //  .
            //  .
            //  .
            //


            StringBuilder stringBuilder = new StringBuilder();
            split.ToList().ForEach(n => stringBuilder.AppendFormat("{0}|", n));

            string strOut = stringBuilder.ToString();


Example:2


        List<string> itemArray = new List<string>()
            {
                 "CUSTOMERNAME","FIRST CROSS"
            };

            List<string> masterlst = new List<string>()
            {
                "CUSTOMERNAME","CUSTOMERNA","B","B1"
            };

            List<string> ptrn = new List<string>();
            itemArray.ForEach(n => ptrn.Add(masterlst.Find(n.Contains)));



No comments:

Post a Comment

Code Formater

Paste Here Your Source Code
Source Code Formatting Options
1) Convert Tab into Space :
2) Need Line Code Numbering :
3) Remove blank lines :
4) Embeded styles / Stylesheet :
5) Code Block Width :
6) Code Block Height :
7) Alternative Background :
Copy Formatted Source Code
 
Preview Of Formatted Code