使用保存在文本框中并自行更改的地址("\\") [英] use an address that saved in a textBox and changed itself ("\\")

查看:73
本文介绍了使用保存在文本框中并自行更改的地址("\\")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

我正在使用一些遇到很大问题的链接!!!
我使用openfiledialog获取某些文件的地址,并将它们保存在文本文件中.
当我想使用它并使用这些地址打开文件时,vs从我的代码中获取了一个错误,并说该地址是错误的.出什么问题了?是的,在地址中使用的是"\\"而不是"\",因此我无法打开它,并且由于Visual Studio(c#)无法识别,因此无法将"\\"更改为"\" "\",并且如果在使用时在每个位置都使用"\",则vs会将其更改为"\\"本身.((花费的时间太长))

最后,我想知道如何使用保存的地址打开文件?

-------
有些人无法理解问题,因此我将其弄清楚:您知道如果我们获得文件的路径,则可以将其放在字符串文件中,然后使用它来打开文件.因此这没问题,但是当我们将路径字符串放入文本文件中并在其他位置使用时,当我们调用文本文件并从中获取路径时,我们现在无法使用该路径打开文件因为这次更改了路径,所以"\"更改为"\\",并且代码显示路径错误,无法打开它...
那么我该怎么办才能打开一个文件并保存在文本文件中的路径?
-------
关于您说的"originalGriff"是正确的,即使更改了以下内容,保存在文本文件中的主路径也不会更改,但是代码中不会更改:
手动将字符串路径="F:\\ Autorun.inf"转换为"F:\ Autorun.inf",它显示一条消息,指出vs无法识别...
那我该怎么打开文件?



祝你好运

Hi everybody!

i was using with some links that i faced with a big problem!!!
i used openfiledialog to get address of some files and i saved them in a text file.
when i wanted to use it and open a file with those addresses vs get a bug from my codes and said the address is wrong. what was the problem? yes in the address was used "\\" instead of "\" so i couldn''t open it and it wasn''t possible to change the "\\" to "\" because visual studio (c#) could not recognize "\" and if you use "\" in every place when you are using it, vs changes it to "\\" itself .((it took too long))

at last i wanna know how can i open a file with a saved address ?

-------
some ones couldn''t understand the problem so i make it clear: you know if we get a path of a file we can put it in a string file then use it to open a file. so that''s no problem but when we put the string of path in a text file and use it in another place, when we call the text file and get the path from it, we now we can not open the file with that path because this time the path is changed, the "\" changed to "\\" and the code says the path is wrong an can''t open it...
so what should i do to open a file with a path that saved in a text file?
-------
about that you said "originalGriff" you are right, the master path that saved in the text file isn''t change but in the codes even if you change the:
string path = "F:\\Autorun.inf" to "F:\Autorun.inf" manually it shows a message that said vs can''t recognize it...
so what should i do to open the file?



Good Luck

推荐答案

不确定自己要问什么,但这可能对您有帮助:

如果您在谈论代码中的字符串,请在字符串允许您使用\而不转义它们之前尝试使用
Not really sure what you''re asking, but this might help you:

If you''re talking about a string in your code, try something like
string filename = @"path\to\file";

@之类的东西.如果该字符串来自另一个来源(从文件/文本框/等读取),则在该来源中只需要一个\,它将为您正确地转义.

the @ before a string allows you to use \ without escaping them. If the string is coming from another source (read in from a file/textbox/etc.) then you only need one \ in that source, it will be properly escaped for you.


VS不会更改任何内容-它始终将单个反斜杠字符显示为双精度-因此您可以将"hello \ newline"区分为两行"hello"和"ewline",并将其区分为两个单词"hello"和"newline" 以反斜杠分隔.

它只会影响调试器的显示-不会以任何方式影响文件内容.
使用记事本或类似工具打开文本文件,您将明白我的意思.

您的问题出在其他地方!检查您在其中读取地址的代码以及如何使用它们.
VS does not change anything - it just always shows a single backslash character as a double - so you can tell the difference between "hello\newline" as two lines "hello" and "ewline" and it as two words "hello" and "newline" separated by a backslash.

It only affects the debugger display - it does not affect the file content in any way.
Open your text file with notepad or similar and you will see what I mean.

Your problem lies elsewhere! Check the code where you read the addresses, and how you use them.


恐怕您将不得不向我们展示代码.你说的话没有任何意义.如果您正在调试,则IDE会在实际字符串为"F:\ Autorun.inf"时显示"F:\\ Autorun.inf".因此,当您手动说"F:\ Autorun.inf"会显示一条消息时,这是正确的,因为您正在尝试打开路径为" F:utorun.inf的文件,因为A被转义了.

如果要从保存的文件中读取路径,则无需对字符串做任何操作即可将其用作打开文件的路径.

向我们展示您用来保存文件路径并回读它们的代码,然后我们可能会提供帮助.
I am afraid that you will have to show us the code. What you are saying does not make any sense. If you are debugging the the IDE will show you "F:\\Autorun.inf" when in reality the string is "F:\Autorun.inf". So when you say that ""F:\Autorun.inf" manually it shows a message", that is correct because you are trying to open a file with the path of "F:utorun.inf" because the A is being escaped.

If you are reading the paths from a file that you saved, you should not have to do anything to the string to use it as a path to open a file.

Show us the code that you are using to save the paths to the file and read them back and then we might be able to help.


这篇关于使用保存在文本框中并自行更改的地址("\\")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆