Murachs visual basic 2005 c9 2006 mike murach

This preview shows page 34 - 43 out of 46 pages.

Murach’s Visual Basic 2005, C9 © 2006, Mike Murach & Associates, Inc. Slide 34
Image of page 34

Subscribe to view the full document.

Code that uses the Substring, ToUpper, and ToLower methods Dim firstName As String = "anne" Dim firstLetter As String _ = firstName.Substring(0, 1).ToUpper() Dim otherLetters As String _ = firstName.Substring(1).ToLower() firstName = firstLetter & otherLetters ' Anne Code that copies one string to another string Dim s1 As String = "abc" Dim s2 As String = s1 ' This creates a new string with the value "abc" s2 = "def" ' This doesn't change the value stored in s1 If the last statement was s1 = “def”, does it change the value of s2? Murach’s Visual Basic 2005, C9 © 2006, Mike Murach & Associates, Inc. Slide 35
Image of page 35
Code that parses a first name from a name string Dim fullName As String _ = " Edward C Koop " ' " Edward C Koop " fullName = fullName.Trim() ' "Edward C Koop" Dim firstSpace As Integer = fullName.IndexOf(" ") ' 6 Dim firstSpace As Integer fullName.IndexOf( ) 6 Dim firstName As String = "" If firstSpace = -1 Then firstName = fullName Else firstName _ = fullName.Substring(0, firstSpace) ' "Edward" End If Murach’s Visual Basic 2005, C9 © 2006, Mike Murach & Associates, Inc. Slide 36
Image of page 36

Subscribe to view the full document.

Code that adds hyphens to a phone number Dim phoneNumber As String = "9775551212" phoneNumber = phoneNumber.Insert(3, "-") phoneNumber = phoneNumber.Insert(7, "-") ' 977-555-1212 Code that replaces the hyphens with slashes Dim birthDate As String = "12-27-2007" birthDate = birthDate.Replace("-", "/") ' 12/27/2007 Murach’s Visual Basic 2005, C9 © 2006, Mike Murach & Associates, Inc. Slide 37
Image of page 37