Presentation is loading. Please wait.

Presentation is loading. Please wait.

3.4 Strings Variables and Strings Using Text Boxes for Input and Output Concatenation ANSI Character Set String Properties and Methods: LengthToUpper TrimToLower.

Similar presentations


Presentation on theme: "3.4 Strings Variables and Strings Using Text Boxes for Input and Output Concatenation ANSI Character Set String Properties and Methods: LengthToUpper TrimToLower."— Presentation transcript:

1 3.4 Strings Variables and Strings Using Text Boxes for Input and Output Concatenation ANSI Character Set String Properties and Methods: LengthToUpper TrimToLower IndexOfSubstring

2 Strings continued The Empty String Initial Value of a String Option Strict Internal Documentation Line-Continuation Character

3 Variables and Strings Private Sub btnDisplay_Click(...) Handles btnDisplay.Click Dim today As String today = "Monday" With lstOutput.Items.Clear().Add("hello").Add(today) End With End Sub

4 Using Text Boxes for Input and Output The contents of a text box is always a string Input example strVar = txtBox.Text Output example txtBox.Text = strVar

5 Data Conversion Because the contents of a text box is always a string, sometimes you must convert the input or output numVar = CDbl(txtBox.Text) txtBox.Text = CStr(numVar) Converts a String to a Double Converts a number to a string Demo – oneplusone

6 Concatenation Combining two strings to make a new string quote1 = "The ballgame isn't over, " quote2 = "until it's over." quote = quote1 & quote2 txtOutput.Text = quote & " Yogi Berra" Displays The ball game isn't over until it's over. Yogi Berra Demo – oneplusone modified - ANSI

7 ANSI Character Set A numeric representation for every key on the keyboard See Appendix A in text book – p. 579 Chr() function displays the value

8 String Properties and Methods: "Visual".Length is 6. "Visual".ToUpper is VISUAL. "123 Hike".Length is 8. "123 Hike".ToLower is 123 hike. "a" & " bcd ".Trim & "efg" is abcdefg.

9 More String Properties and Methods: "fanatic".Substring(0, 3) is "fan". "fanatic".IndexOf("ati") is 3. "fanatic".Substring(4, 2) is "ti". "fanatic".IndexOf("a") is 1. "fanatic".Substring(4) is "tic". "fanatic".IndexOf("nt") is –1. Demo 3-4-6

10 The Empty String The string "", which contains no characters, is called the empty string or the zero-length string. The statement lstBox.Items.Add("") skips a line in the list box. The contents of a text box can be cleared with either the statement txtBox.Clear() or the statement txtBox.Text = ""

11 Initial Value of a String By default the initial value is Nothing Strings can be given a different initial value as follows: Dim today As String = "Monday"

12 Option Strict VB.NET allows numeric variables to be assigned strings and vice versa, a poor programming practice. To turn this feature off, put the following statement at the very top of the code window Option Strict On Demo: Commission / oneplusone

13 Internal Documentation 1.Other people can easily understand the program. 2.You can understand the program when you read it later. 3.Long programs are easier to read because the purposes of individual pieces can be determined at a glance.

14 Line-Continuation Character A long line of code can be continued on another line by using underscore (_) preceded by a space msg = “This is not the end " & _ “of this line!"

15 Exercises p. 100 - 106 3-4-53 together p. 105 Homework – 3-4-45 p. 104


Download ppt "3.4 Strings Variables and Strings Using Text Boxes for Input and Output Concatenation ANSI Character Set String Properties and Methods: LengthToUpper TrimToLower."

Similar presentations


Ads by Google