Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

Comparison on string with escape character

$
0
0

I have the following scenario:

  • Text stored in the database as folder\folder\subfolder
  • As soon as I read it into a string variable (directoryPath) in c#, when I look at it in the debugger it appears as folder\\folder\\subfolder
  • I call directoryPath.IndexOfAny(System.IO.Path.GetInvaildFileNameChars()) and it returns a positive integer indicating that a match was found (\\) - but it shouldn't be found at all because that really doesn't exist in the string.

How do I do this comparison so that it ignores the escape character in the source string?

I've been reading posts on here for quite a while on the escape character and string literals and pretty much every one I have read is dealing with when you are actually setting the variable and explicitly escaping the \ in the directory path or using the @ symbol. The path is being entered by a user from a textbox right into a viewmodel property, I am not hard-coding a string so I think any of that really applies. My issue is that the escape characters are already in the string as soon as I pull the string from the database (record is NOT stored with escape character) and I need to do a comparison and make sure that "\\" does not actually exist in the string.

Any thoughts?

Thank you!



Viewing all articles
Browse latest Browse all 31927

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>