I have hit another roadblock and need some help: In windows, a filename like "A330 amu.jpg" is exactly the same as "a330 amu.jpg". In VB.NET, "A330 amu.jpg" is not the same as "a330 amu.jpg". Is there a way to make "A330 amu.jpg" = "a330 amu.jpg" true in VB.NET? I am making a program that cross references folder paths with jpg's inside the program's cwd(Current Working Directory). Also, this is not the only instence where there are differences like this. There are many more. I have also tried the str.Contains() method as well with no success. Basically I need to be able to load files regardless of case(case insensitive) just like the OS does. Python has this built into it. In other words: How do I get vb.net to honor the file system rules already built into the OS itself? Thanks!
Asked
Active
Viewed 153 times
1
-
http://stackoverflow.com/questions/813335/is-vb6-string-comparison-case-insensitive – Miserable Variable Dec 18 '12 at 19:38
-
1http://superuser.com/questions/364057/why-is-ntfs-case-sensitive – Sam Axe Dec 18 '12 at 20:13
1 Answers
3
You need to specify a string comparison type:
"Foo".Equals("foo", StringComparison.CurrentCultureIgnoreCase)
If you're not sure how to use this in your code, update your question to include a sample of the code where you're making the comparison.

Jon B
- 51,025
- 31
- 133
- 161
-
1Is there a way, though, to make it honor the rules of the current file system, whatever that happens to be? For instance, in windows, both the shortened and full length version of the file name both equate to the same actual file. (that wan't me voting you down by the way) – Steven Doggart Dec 18 '12 at 19:40
-
@StevenDoggart - I've never come across that. There's a `GetLongPathName` function in kernel32.dll -- you can use that to handle the short names vs long names (by turning them all into long names). – Jon B Dec 18 '12 at 19:46
-
Right. You can actually use `Path.GetFullPath` and then compare those with a case insensitive comparison. However, that doesn't work with network file shares and it assumes that the OS is always case insensitive, which may not be the case. It's an interesting question. I found some interesting answers here: http://stackoverflow.com/questions/410705/best-way-to-determine-if-two-path-reference-to-same-file-in-c-sharp – Steven Doggart Dec 18 '12 at 19:51
-
Steven, Your first comment is what I want to accomplish. How do I get vb.net to accept the rules of the filesystem? – Josh Menzel Dec 18 '12 at 20:07
-
@JoshMentwizzler There is no built-in way to do this. You can, however, figure this out -- see here: http://stackoverflow.com/questions/430256/how-do-i-determine-whether-the-filesystem-is-case-sensitive-in-net – Jon B Dec 18 '12 at 20:09
-
Thanks for the help! Based on what you suggested in the links and the code above, I was able to work something out! Thanks again! – Josh Menzel Dec 19 '12 at 23:34