VB.NET Cheat Sheet By: Andrew Kiceniuk s2

Total Page:16

File Type:pdf, Size:1020Kb

VB.NET Cheat Sheet By: Andrew Kiceniuk s2

VB.NET Cheat Sheet By: Andrew Kiceniuk Unit 3: Strings Structure of a String: Strings are a series of characters (data type: Char) that are strung together, hence the name String. Each character has a position number within the String, often referred to as an index number. Example: Dim strFirstName As String = “Sarah” characters S a r a h 0 1 2 3 4 index numbers

This String has a length of 5 (it has 5 characters). But it has index numbers 0 - 4.

String Concatenation: Is the process of joining multiple String values together to form one String. You concatenate multiple Strings using the (&) symbol. Strings can be formatted to contain multiple lines by concatenating a new line (vbCrLf) into the String. Example: Dim strFirstName As String = “Sarah” Displays As: Dim strLastName As String = “Smith” Sarah Me.lblFullName.Text = strFirstName & vbCrLf & strLastName Smith

Parsing Strings: Parsing is the process of cutting up Strings so that they can be manipulated by your program. The String class contains many methods for parsing Strings. Methods are essentially mini programs. Below is a list of some of the common methods used for parsing and manipulating Strings. For each method listed below there must be a String variable in front of the dot.

.Length() Returns number of characters in the String.

Example: intNumLetters = strFirstName.Length In this example intNumLetters will have the value 5 .Substring(intStartPosition, # of Chars) Returns the specified number of characters starting at the String index intStartPosition

Example: strEygptianGod = strFirstName.Substring(2,2)In this example strEgyptianGod will have the value “ra” .Substring(intStartPos) Returns a portion of the String starting at the index number intStartingPos and going to the end of the String.

Example: strSurprise = strFirstName.Substring(3) In this example strSurprise will have the value “ah” .Chars(intIndex) Returns the character at the given String index value

Example: strLetter = strFirstName.Chars(3) In this example strLetter will have the value of “a” .IndexOf(“Search String”) Returns the String index number of where the 1st occurrence of the ‘Search String’ begins.

Example: intPosFound= strFirstName.IndexOf(“a”) In this example intPosFound will have the value 1 intPosFound= strFirstName.IndexOf(“A”) In this example intPosFound will have a value of -1 because the ‘Search String’ , “A”, could not be found. .ToUpper() Returns the String in all uppercase letters .ToLower() Returns the String in all lowercase letters VB.NET Cheat Sheet By: Andrew Kiceniuk Unit 3: Strings Example: strFirstName = strFirstName.ToUpper() In the example strFirstName will have the value “SARAH”

Recommended publications