-
For Loop Debug
I was making an invalid character removal module for my program, and here is the function that I used:
Code:
Function fix_extensions(file_extension As String)
'Fixes file extensions
Dim banned_ext_chars() As String = {"\", "/", ":", ";", "*", "?", """", "<", ">", "|", "%", ",", "#", "$", "!", "+", "{", "}", "&", "[", "]", "•", "'", "."}
For index As Integer = 1 To banned_ext_chars.Length - 1
file_extension = file_extension.Replace(banned_ext_chars(index), "")
Next
file_extension = "." & file_extension
Return file_extension
End Function
However, upon checking the output through a short debug, it appears that the backslash was never filtered out. I've tried many things, but none worked.
Help would be greatly appreciated.
-
Re: For Loop Debug
Hi,
All collections in VB.NET, including Arrays, are indexed from Zero. Therefore your For Loop is incorrect. It should be:-
Code:
For index As Integer = 0 To banned_ext_chars.Length - 1
Hope that helps.
Cheers,
Ian
-
Re: For Loop Debug
Ah, yes. Of course. Just a little carelessness...
-
Re: For Loop Debug
Quote:
Code:
For index As Integer = 1 To banned_ext_chars.Length - 1
What's the index of the backslash in your array of banned characters?