Key - Enrichment Mod 14

advertisement
Computer Programming I
Module 14 Enrichment
Indicator 7.03 Apply Built-in Math Functions (3%)
Indicator 7.04 Apply Built-in String Functions (3%)
Earn 2 points for each correctly answered question to be added to your test score. Make sure
you include the questions. Change the color of your answer so they are easy to read for your
instructor.
1. What does the Length property do?
a. Give the number of characters in a string
2. Complete the code to find the length of the string strAnimal.
intLength = strAnimal.Length
3. What does the Chars property do?
a. Get the character at that index position
4. Given a string called strWord, complete the code to find each of the following.
a. The first letter
chrLetter = strWord.Chars(0)
b. The last letter
intLastIndexPos = strword.Length – 1
chrLastLetter = strWord.Chars(intLastIndexPos)
c. The middle letter
intMidIndexPos = strword.Length /2
chrMidLetter = strWord.chars(intMidIndexPos )
5. What is the output of the following code?
a. Peanut comes after Butter
Dim strA As String = "Peanut"
Dim strB As String = "Butter"
If String.Compare(strA, strB) = 0 Then
lblAnswer.Text = strA & " is equal to " & strB
ElseIf String.Compare(strA, strB) < 0 Then
lblAnswer.Text = strA & " comes before " & strB
ElseIf String.Compare(strA, strB) > 0 Then
lblAnswer.Text = strA & " comes after " & strB
End If
6. What is the output of the following code?
a. Programming Rocks
Dim strA As String = "Programming"
Dim strB As String = " Rocks"
Dim strNew As String
strNew = String.Concat(strA, strB)
lblAnswer.Text = strNew
7. What is the output of the following code?
The strings are the different.
Dim strA As String = "Apple"
Dim strB As String = "apple"
If strA.Equals(strB) Then
lblAnswer.Text = "The strings are the same."
Else
lblAnswer.Text = "The strings are the different."
End If
8. What is the output of the following code?
11
Dim strA As String = "Programming rocks!"
Dim intIndex As Integer
intIndex = strA.IndexOf(" ")
lblAnswer.Text = intIndex
9. What is the output of the following code?
Apesx
Dim strA As String = "Apex"
Dim strNew As String
strNew = strA.Insert(3, "s")
lblAnswer.Text = strNew
10. What is the output of the following code?
Programing
Dim strA As String = "A"
Dim strB As String = "Programming"
Dim strNew, strNew2 As String
strNew = strA.Remove(1)
strNew2 = strB.Remove(6, 1)
lblAnswer.Text = strNew2 & " " & strNew
11. What is the output of the following code?
Apex prograing
Dim strA As String = "Apex"
Dim strB As String = "Programming"
Dim strNew, strNew2 As String
strNew = strA.Replace("a", " ")
strNew2 = strB.Replace("m", "")
lblAnswer.Text = strNew & " " & strNew2
12. What is the output of the following code?
ApexHigh
Dim strA As String = "
Apex
Dim strB As String = "High "
strA = strA.TrimEnd
lblAnswer.Text = strA & strB
"
Download