Backslashes and forward slashes
-
string withForwardSlashes = withBackwardSlashes.Replace('\\', '/');
or
string withForwardSlashes = withBackwardSlashes.Replace("\\", "/");
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
-
I am retrieving a filepath that I need in my program using a folderBrowserDialog. Can anyone tell me how to change all the back slashes to forward slashes? Thanks Darrall
Darrall wrote:
Can anyone tell me how to change all the back slashes to forward slashes?
For what purpose? In Windows, the standard path seperator is a backslash while the forward slash is used for command line switches.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009... -
Darrall wrote:
Can anyone tell me how to change all the back slashes to forward slashes?
For what purpose? In Windows, the standard path seperator is a backslash while the forward slash is used for command line switches.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009...I am using folderBrowserDialog to locate the folder where the user stored his program which also has the location of the data files which are needed for the program. The path is returned as it is in the computer with backslashes but can't be used that way by the program.
-
I tried it exactly as you have it there and I get "Too many characters in character literal" and "No overload for method 'Replace' takes '1' arguments." Any thoughts? Thanks for your time. Darrall
Works fine for me - could you post the code fragment exactly as you have it?
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
-
I tried it exactly as you have it there and I get "Too many characters in character literal" and "No overload for method 'Replace' takes '1' arguments." Any thoughts? Thanks for your time. Darrall
Darrall wrote:
Any thoughts?
Yes, two:
- Did you type carefully?
- Post your code if you want us to help you fix it.
/ravi
My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com
-
Works fine for me - could you post the code fragment exactly as you have it?
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
Here it is :)
private void button2_Click(object sender, EventArgs e)
{
string OldPathName;
string NewPathName;if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) { MessageBox.Show("MyFolder = " + folderBrowserDialog1.SelectedPath); textBox1.Text = folderBrowserDialog1.SelectedPath; OldPathName = NewPathName.Replace ('\\','/'); }
-
Here it is :)
private void button2_Click(object sender, EventArgs e)
{
string OldPathName;
string NewPathName;if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) { MessageBox.Show("MyFolder = " + folderBrowserDialog1.SelectedPath); textBox1.Text = folderBrowserDialog1.SelectedPath; OldPathName = NewPathName.Replace ('\\','/'); }
-
Backslash is an escape character. The
'\'
you entered is interpreted as''
. You can change that to@'\'
or'\\'
and it should work.Don't blame me. I voted for Chuck Norris.
-
I am using folderBrowserDialog to locate the folder where the user stored his program which also has the location of the data files which are needed for the program. The path is returned as it is in the computer with backslashes but can't be used that way by the program.
Darrall wrote:
can't be used that way by the program
Fix the program.
-
Here it is :)
private void button2_Click(object sender, EventArgs e)
{
string OldPathName;
string NewPathName;if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) { MessageBox.Show("MyFolder = " + folderBrowserDialog1.SelectedPath); textBox1.Text = folderBrowserDialog1.SelectedPath; OldPathName = NewPathName.Replace ('\\','/'); }
I take it from the other responses that that problem is fixed? Now change your code slightly to make it actually work!
private void button2_Click(object sender, EventArgs e)
{
string OldPathName;
string NewPathName;if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) { MessageBox.Show("MyFolder = " + folderBrowserDialog1.SelectedPath); NewPathName = folderBrowserDialog1.SelectedPath; textBox1.Text = NewPathName; OldPathName = NewPathName.Replace ('\\\\','/'); }
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy