How to get comma separated words with single quote in C#?

LINQ  Get comma separated words with single quote in C#

  1. First parameter itemCollection is input  |   Hello+we+are+here 
  2. Second parameter separator is char      |    ‘+
        C# sample Code 


        public static string GetResults(string itemCollection,char separator)

        {

            string result = string.Empty;

            if (String.IsNullOrEmpty(itemCollection)) return result;
            else
            {
                result = string.Join(“,”, itemCollection.Split(separator).Select(x => string.Format(“‘{0}'”, x.TrimStart().TrimEnd())).ToList());                
            }
            return result;
        }

Input:  Hello+we+are+here 


Output :  ‘Hello’,’we’,’are’,’here ‘


Published by arjunpremier

Software Engineer, Blogger,

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Design a site like this with WordPress.com
Get started