VB Math All of your favorite mathematical operators

VB Math • All of your favorite mathematical operators are available in VB: • + Addition • - Subtraction • * Multiplication • / Division • Integer Division • Modulo (remainder after integer division) • ^ Exponentiation

Other Math Functions • Trig functions, logarithms, and other advanced math functions are available in the Math class (built in to VB). • To use these, just type the word “Math” followed by a period into your code; all of your options will appear in the intellisense drop-down list.

String Operator • VB strings are powerful and easy to use. • A string variable can hold extremely long strings (millions of characters). • The basic string operator is the ampersand (&). It concatenates (puts together) two strings: Dim s As String = “Go “ Dim t As String = “Blue!” Dim u As String = s & t u will have the value “Go Blue!”

String Functions • VB. NET offers many useful string functions • Most can be accessed simply by typing a period after a string variable:

String Functions • Some of the most useful string functions are: – Length: how many characters in the string – Contains: Boolean indicating if one string is inside another – Index. Of: If one string is inside another, this tells you where it begins – Starts. With, Ends. With: Boolean indicating whether one string begins or ends with another – Insert, Remove, Replace: Common editing functions – Substring: Pulls out a part of a string starting with a given character – Split: Takes a string and creates an array of strings which are the original string divided up at a given character (like spaces for words or periods for sentences). – To. Upper, To. Lower: Converts the string’s case.

Shortcut assignment operators • VB. NET supports shortcut operators (+=, -=, *=, /=, &=, etc. ): • A += B is the same as A = A + B • X *= 4 is the same as X = X * 4 • S &= “!” is the same as S = S & “!”
- Slides: 6