If you want to make sure the first character of a string is one slash, use the function:
public string PrependPath(string path, string firstCharacter) { return firstCharacter + path.TrimStart(firstCharacter.ToCharArray()); }
To test the function use:
string firstCharacter = "/"; Console.WriteLine(PrependPath("TestPath", firstCharacter)); Console.WriteLine(PrependPath("/TestPath", firstCharacter)); Console.WriteLine(PrependPath("//TestPath", firstCharacter)); Console.WriteLine(PrependPath("///TestPath", firstCharacter));
Result
/TestPath
/TestPath
/TestPath
/TestPath