Substring size advice
If using the following in an if statement I get an error:
If trg.Name.Substring(4, 6).ToUpper <> ("ABCDEF") Then
I get the error: "Index and length must refer to a location within the string. Parameter name: length"
I assume this is because the string (trg.name) is too small for the开发者_Python百科 4, 6 substring. What would be the correct method of working around this problem?
Thanks, madlan.
VB.net Studio 2008.
If (trg.Name.IndexOf("ABCDEF", StringComparison.OrdinalIgnoreCase) <> 4) Then
Instr returns the index of where the searched string is first found. So If you could do this:
If InStr(trg.Name, "ABCDEF", CompareMethod.Text) - 1 <> 4 Then
With InStr you dont have to check lenght of trg.Name.
You should likely be checking that the length of trg.Name
is at least (4+6) characters long.
精彩评论