Replace Illegal Characters - CSharp System

CSharp examples for System:String Replace

Description

Replace Illegal Characters

Demo Code


using System.Text.RegularExpressions;
using System.Text;
using System.Globalization;
using System.Collections.Generic;
using System;/*www.ja v a2  s  .co m*/

public class Main{
        public static string ReplaceIllegalCharacters(string input, string replaceWith)
        {            
                String T2 = input.Replace("\\", replaceWith);
                T2 = input.Replace("/", replaceWith);
                input = T2.Trim();
                T2 = input.Replace(":", replaceWith);
                input = T2.Trim();
                T2 = input.Replace("?", replaceWith);
                input = T2.Trim();
                T2 = input.Replace("\"", replaceWith);
                input = T2.Trim();
                T2 = input.Replace("<", replaceWith);
                input = T2.Trim();
                T2 = input.Replace(">", replaceWith);
                input = T2.Trim();
                T2 = input.Replace("|", replaceWith);
                input = T2.Trim();
                T2 = input.Replace("*", replaceWith);
                input = T2.Trim();
                T2 = input.Replace("  ", " ");
                input = T2.Trim();
                return input;
        }
}

Related Tutorials