Normalize Path String - CSharp File IO

CSharp examples for File IO:Path

Description

Normalize Path String

Demo Code


using System.Text.RegularExpressions;
using System.Text;
using System.Globalization;
using System.Collections.Generic;
using System;/*from  ww w .  ja  v a  2 s. co  m*/

public class Main{
        internal static string NormalizePath(string path)
            {

                try
                {
                    path = path.Replace(':', '-');
                    path = path.Replace('/', '-');
                    //Path = Path.Replace('\\', '-');
                    path = path.Replace('*', '\'');
                    path = path.Replace('?', ';');
                    path = path.Replace('"', '\'');
                    path = path.Replace('<', '[');
                    path = path.Replace('>', ']');
                    path = path.Replace('|', '-');
                }
                catch (Exception e)
                {
                    Debugger.LogMessageToFile("An unexpected error occurred in the String Normalizer. " +
                                              "The error was: " + e );

                }



                return path;
            }
}

Related Tutorials