Skip to main content

Posts

Showing posts with the label String Manipulation in C#

Coding Challenge: C# program to find the given string is a Pangram

Coding Challenge to find the given string is a Pangram or not Pangram is a string which will contain all the alphabets (a-z) Example:  "The quick brown fox jumps over the lazy dog" From Wikipedia  Conditions: * Spaces allowed in the input  * Check the given string contains at least once of all the alphabets a-z * Case in sensitive         public static bool CheckIsPangram( string str)         {             List < string > LstAtoZ =                                Enumerable .Range( 'A' , 26)                               .Select(x => ( char )x + "" )                               .ToList();                          str = str.Replace( " " , "" );               foreach ( char chr in str)             {                 if (LstAtoZ.Contains(chr.ToString().ToUpper()))                 {                     LstAtoZ.Remove(chr.ToString().ToUpper());                 }             }             retur

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 += "