Replace Line Breaks in a String C#

Use replace with Environment.NewLine myString = myString.Replace(System.Environment.NewLine, “replacement text”); //add a line terminating ; As mentioned in other posts, if the string comes from another environment (OS) then you’d need to replace that particular environments implementation of new line control characters.

Copy the entire contents of a directory in C#

Much easier private static void CopyFilesRecursively(string sourcePath, string targetPath) { //Now Create all of the directories foreach (string dirPath in Directory.GetDirectories(sourcePath, “*”, SearchOption.AllDirectories)) { Directory.CreateDirectory(dirPath.Replace(sourcePath, targetPath)); } //Copy all the files & Replaces any files with the same name foreach (string newPath in Directory.GetFiles(sourcePath, “*.*”,SearchOption.AllDirectories)) { File.Copy(newPath, newPath.Replace(sourcePath, targetPath), true); } }

Declare a const array

Yes, but you need to declare it readonly instead of const: public static readonly string[] Titles = { “German”, “Spanish”, “Corrects”, “Wrongs” }; The reason is that const can only be applied to a field whose value is known at compile-time. The array initializer you’ve shown is not a constant expression in C#, so it … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)