CSharp examples for Language Basics:string
Get rid of special characters in a string using split
using System;//from ww w . ja v a2s .c o m public class Program { public static void Main(string[] strings) { char[] whiteSpace = {' ', '\n', '\t'}; string s = " this is a\nstring"; Console.WriteLine("before:" + s); Console.WriteLine("after:" + RemoveSpecialChars(s, whiteSpace)); } public static string RemoveSpecialChars(string input, char[] targets) { string[] subStrings = input.Split(targets); string output = ""; foreach(string subString in subStrings) { output = String.Concat(output, subString); } return output; } }