Zero-based vs. One-based String Access in Visual Basic

This topic compares how Visual Basic and the .NET Framework provide access to the characters in a string. The .NET Framework always provides zero-based access to the characters in a string, whereas Visual Basic provides zero-based and one-based access, depending on the function.

One-Based

For an example of a one-based Visual Basic function, consider the Mid function. It takes an argument that indicates the character position at which the substring will start, starting with position 1. The .NET Framework String.Substring method takes an index of the character in the string at which the substring is to start, starting with position 0. Thus, if you have a string "ABCDE", the individual characters are numbered 1,2,3,4,5 for use with the Mid function, but 0,1,2,3,4 for use with the String.Substring method.

Zero-Based

For an example of a zero-based Visual Basic function, consider the Split function. It splits a string and returns an array containing the substrings. The .NET Framework String.Split method also splits a string and returns an array containing the substrings. Because the Split function and Split method return .NET Framework arrays, they must be zero-based.

See Also

Tasks

Troubleshooting Collections

Reference

Mid Function (Visual Basic)

Split Function (Visual Basic)

Substring

Split

Other Resources

Introduction to Strings in Visual Basic