30.07.2013 Views

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

642 Strings, Characters and Regular Expressions Chapter 15<br />

1 ' Fig. 15.4: StringStartEnd.vb<br />

2 ' Demonstrating StartsWith and EndsWith methods.<br />

3<br />

4 Imports System.Windows.Forms<br />

5<br />

6 Module modStartEnd<br />

7<br />

8 Sub Main()<br />

9 Dim strings As String()<br />

10 Dim output As String = ""<br />

11 Dim i As Integer<br />

12 Dim quotes As Char = ChrW(34)<br />

13<br />

14 strings = New String() {"started", "starting", _<br />

15 "ended", "ending"}<br />

16<br />

17 ' test every string <strong>to</strong> see if it starts with "st"<br />

18 For i = 0 To strings.GetUpperBound(0)<br />

19<br />

20 If strings(i).StartsWith("st") Then<br />

21 output &= quotes & strings(i) & quotes & _<br />

22 " starts with " & quotes & "st" & quotes & vbCrLf<br />

23 End If<br />

24<br />

25 Next<br />

26<br />

27 output &= vbCrLf<br />

28<br />

29 ' test every string <strong>to</strong> see if it ends with "ed"<br />

30 For i = 0 To strings.GetUpperBound(0)<br />

31<br />

32 If strings(i).EndsWith("ed") Then<br />

33 output &= quotes & strings(i) & quotes & _<br />

34 " ends with " & quotes & "ed" & quotes & vbCrLf<br />

35 End If<br />

36<br />

37 Next<br />

38<br />

39 MessageBox.Show(output, "Demonstrating StartsWith and" & _<br />

40 " EndsWith methods", MessageBoxBut<strong>to</strong>ns.OK, _<br />

41 MessageBoxIcon.Information)<br />

42 End Sub ' Main<br />

43<br />

44 End Module ' modStartEnd<br />

Fig. 15.4 StartsWith and EndsWith methods.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!