2

I'm writing an application using C#, normally a VB user, so have been thrown a few easily solveable curve balls with the syntax differences, until this...

I have a couple of string paths in my Application Settings e.g. *AppSetting_SourceFolder=C:\SourceFolder* and *AppSetting_DestFolder=C:\DestFolder\Processed*

in my code I have a FileSystemWatcher that is watching the source folder and for certain files that appear in the source folder, they are processed and moved to the destination folder. My issue is that when I pull my folders names from the settings into variables or the FileSystemWatcher they don't comeout as expected.

string sSourcePath = MyNameSpace.Properties.Settings.Default.AppSetting_SourceFolder;
string sDestPath = MyNameSpace.Properties.Settings.Default.AppSetting_DestFolder;

and I watch the variables at runtime is see that sSourcePath contains "C:\\SourceFolder\\" and sDestFolder contains "C:\\DestFolder\\Processed\\"

I've looked at using the string literal @ infront of my setting reference:

string sSourcePath = @MyNameSpace.Properties.Settings.Default.AppSetting_SourceFolder;
string sDestPath = @MyNameSpace.Properties.Settings.Default.AppSetting_DestFolder;

and also infront of my variable name:

string @sSourcePath = MyNameSpace.Properties.Settings.Default.AppSetting_SourceFolder;
string @sDestPath = MyNameSpace.Properties.Settings.Default.AppSetting_DestFolder;

and also infront of my both parts:

string @sSourcePath = @MyNameSpace.Properties.Settings.Default.AppSetting_SourceFolder;
string @sDestPath = @MyNameSpace.Properties.Settings.Default.AppSetting_DestFolder;

but the outcome doesn't change. What do i have to do to get rid of the extra \'s?

Just to note, when I watch @MyNameSpace.Properties.Settings.Default.AppSetting_SourceFolder and @MyNameSpace.Properties.Settings.Default.AppSetting_DestFolder; the result is the same (lots of double \'s).

What am doing (or not doing) wrong? Thanks Steve

Captsx1
  • 23
  • 2
  • 2
    Nothing. A backslash is used to indicate the next character is a special character like "\n" is a return. So indicate the backslash is a real backslash you use two backslashes. – jdweng Nov 03 '20 at 17:11
  • 2
    N.B. There is a huge difference between an [`@` in front of a variable name or symbol](https://stackoverflow.com/questions/429529/what-does-the-symbol-before-a-variable-name-mean-in-c) and an [`@` in front of a string literal](https://stackoverflow.com/questions/556133/whats-the-in-front-of-a-string-in-c). – John Wu Nov 03 '20 at 17:44
  • @JohnWu, What are the differences? – Captsx1 Nov 03 '20 at 18:33
  • @Captsx1 Click the links – John Wu Nov 03 '20 at 18:55
  • @JohnWu: Doh! Thanks for that :) – Captsx1 Nov 04 '20 at 07:41

1 Answers1

0

These are not double backslashes. When you watch the value by either hovering your mouse pointer at the variable or in the Watch panel, all the special characters that need to be escaped are shown there with additional backslash.

If you want to see processed string without additional backslashes, click the magnifying glass icon near the value.

Watch panel - magnifying glass button

Text Visualizer after clicking the icon

kmicki
  • 16
  • 2