This code prints true and works just fine: Code (CSharp): if (ImportFrom.Replace("\\", "/").Equals("C:/Users/gfell/Documents/item side projects/3D Viewer/01_ImportFolder")) { Debug.Log("true"); } var info = new DirectoryInfo("C:/Users/gfel/Documents/item side projects/3D Viewer/01_ImportFolder"); This one does not print true and throws "ArgumentException: Illigal characters in path": Code (CSharp): if (ImportFrom.Replace("\\", "/").Equals("C:/Users/gfell/Documents/item side projects/3D Viewer/01_ImportFolder")) { Debug.Log("true"); } var info = new DirectoryInfo(ImportFrom.Replace("\\", "/")); How come?
Did you try printing out what the string is after you do the replace? If it's not printing true, then your ImportFrom string would appear to have an illegal char in it and it doesn't match your path string.
I tested a bit and using a veriable actually does work. so saying this is just fine: Code (CSharp): ImportFrom = "C:\\Users\\gfell\\Documents\\item side projects\\3D Viewer\\01_ImportFolder"; if (ImportFrom.Replace("\\", "/").Equals("C:/Users/gfell/Documents/item side projects/3D Viewer/01_ImportFolder")) { Debug.Log("true"); } var info = new DirectoryInfo(ImportFrom.Replace("\\", "/")); But I want to extract the path out of an txt file. This is what I do for that: Code (CSharp): public string ImportFrom; public string MoveTo; public string ExportTo; public TextAsset txtLinkFile; void Start() { setLinks(txtLinkFile.text); } public void setLinks(string text) { string[] links = text.Split('\n'); ImportFrom = links[0]; MoveTo = links[1]; ExportTo = links[2]; } With this inside my txt file: C:\Users\gfell\Documents\item side projects\3D Viewer\01_ImportFolder C:\Users\gfell\Documents\item side projects\3D Viewer\00_Archive C:\Users\gfell\Documents\item side projects\3D Viewer\02_Exported When I print it the console I get the same outputs of ImportFrom. Why does the string extracted from an txt file behaves different than the hardcoded?
As mentioned, please print out your string for us. Don't use Debug.Log(true), but print out the actual path. Do your replace into a variable, and print it out.
So in setLinks you should be printing out each value before the replace. After doing the replace you should also be printing out the value. Also, just curious, but why do you need to do a replace instead of just including the path with the slashes as you need them? Otherwise, if both your printouts seem fine, you may need to loop through the chars in the string and see if you notice anything odd. Depending on how you created the txt file, there are sometimes hidden chars that can be created. You may just consider using notepad and create the txt file again from scratch.
Make sure you're using the correct separators for the line endings. \n is not necessarily the only character that is used, you also find \r\n or sometimes even \n. This might already solve the problem. If it doesn't, debug the code / log the character values as integers.
This was actually it. In the console all strings looked as expacted. with \ or / depending on if .Replace was used or not. But when I opend the .txt in notepad++ and turned on visualizing all characters, I saw "CR LF" on the line endings. So replacing \r\n with \n in the .txt was the solution. Thanks everyone!