VB.NET String

Use the String type: create, search and modify strings. Test string Functions.

String. A string is a collection of characters. In one, we find representations of any kind of data. A large selection of string-based functions are available.

String Functions. For some of these methods, we call them on a string instance. But on others we invoke them from the String type as a Shared Function.CompareCompareOrdinalCompareToConcatContainsCopyCopyToEmptyEndsWithEqualsFormatIndexOfIndexOfAnyInsertIsNullOrEmptyIsNullOrWhiteSpaceJoinLastIndexOfLastIndexOfAnyLengthPadLeftPadRightRemoveReplaceSplitStartsWithSubstringToCharArrayToLowerToLowerInvariantToStringToUpperToUpperInvariantTrimTrimEndTrimStart

Special methods. The VB.NET language includes some special methods made to help with older program. CStr converts to a string. Mid gets a part of a string.CStrLSetLTrimMidRSetRTrim

String constructor. Sometimes we need to create a new string. With the string constructor, we can repeat a character many times in a new string.String Constructor

String loop. We can loop over a string with a For-loop, a For-Each loop or even a While-loop. The ForEach loop is simplest and the best choice for when an index is not needed.String: For, For-Each

First letter. We develop an optimized algorithm for uppercasing the first letter in a String. We can alternatively use ToTitleCase.Uppercase FirstUppercase First: ToTitleCase

NewLine. We can get the newline string in VB.NET with the Environment.NewLine constant. This can make some programs easier to read and clearer.NewLine

Convert. It is often necessary to convert Strings to other types, such as Integers. And most types can be converted to Strings with ToString.String, Byte ArrayString, Char ArrayString, IntegerString, ListString, String Array

Select Case. A String instance can be used in a Select Case statement. A logical decision is made based on the String's character data. In other languages, the switch-statement is similar.Select Case, String

HTML encoding. In HTML pages, we must encode characters like < and >. And in urls we must encode chars like spaces. HtmlEncode and UrlEncode are helpful.HtmlEncode

Custom methods. Built-in Functions are best for manipulating strings in simple ways. But for complex things, we often need custom methods.Custom: Duplicate CharsCustom: LevenshteinCustom: PunctuationCustom: Random StringCustom: ReverseCustom: ROT13Custom: Truncate

A review. The String type is powerful. But it has limitations. In situations where we can improve performance by mutating an existing string, consider a StringBuilder.

© 2007-2020 Sam Allen. Every person is special and unique. Send bug reports to info@dotnetperls.com.