Ire*_*311 0 c# string stringbuilder string-formatting
我做了一些C#程序,它获取了最新创建的文件.
例如它是一个D:\Directory1\file1.txt 文件
当它获取文件时,其文件的地址存储在某个变量中,如此字符串:
"D:\\Directory1\\file1.txt"
当您在调试中观察时,您可以看到此值.
FileInfo f1; // this is a latest created file "D:\Directory1\file1.txt"
string s1 = f1.FullName; // string value will be "D:\\Directory1\\file1.txt"
string s2 = SomeFunction(s1); // in order to get @"D:\Directory1\file1.txt" value
Run Code Online (Sandbox Code Playgroud)
如果将其值分配给不同的变量s2,那么您将再次获得相同的字符串值!
那么如何将此值赋给不同的变量以获得@"D:\ Directory1\file1.txt"值.
我应该使用StringBuilder类吗?
我应该使用String.Format吗?
还是非常感谢!
您在调试器中看到的值是转义的,因为它在C#中.
当使用逐字时@"\",实际上"\\",或者正如我们人类在屏幕上看到的那样\.
不要让你的头被调试器中看到的值弄乱.他们真的没问题.单击手表中的放大镜,您将看到.