Skip to main content

Posts

Showing posts with the label Generate CSV values easily in C#

Generate CSV values easily in C# , String Manipulation in C#

Suppose you are having a List<String> and you are in need to generate a Comma Separated Value (CSV) from this with single quotes attached   Say We need to dynamically generate a simple SQL Select statement from a Order table and the filter criteria would be like this   Select New ('NO') Orders, Active ('AO') Orders and Successful ('SO') Orders Let's we have a Status Codes in a List<String>   The desired output SELECT * FROM ORDERS WHERE STATUS IN ('NO', 'AO', 'SO')   Traditional Solution   TraditionalSolution(StatusCodes);   private static void TraditionalSolution( List < string > StatusCodes) { // Traditionally what we will do is // Loop through the List and generate a SQL Statement   string OutputSQL = "SELECT * FROM ORDERS WHERE STATUS IN (" ;   int Count = StatusCodes.Count(); foreach ( string SingleStatusCode in StatusCodes) { OutputSQL += "