I have a function in where I want to convert a string value C:\samplec#programs\Converter to C:\\samplec#programs\\Converter Note the differences. This is my function:
private string FilePathProcessor(string path)
{
char[] oriCharArray = path.ToCharArray;
List<char> oriCharList = new List<char>;
List<char> newCharList = new List<char>;
foreach (char item in oriCharArray)
{
oriCharList.Add(item);
}
foreach (char items in oriCharList)
{
if ((items != "\\"))
{
newCharList.Add(items);
}
else
{
newCharList.Add(items);
newCharList.Add(items);
}
}
string result = string.Join(",", newCharList.ToArray());
return result;
}
Of course this function serves my needs. But, I wonder if there is already an existing function in .Net which will take care of it. I am just cleaning up my code and checking for simpler and faster solution. Not going to reinvent the wheel if there is already a way.