1. Class String and the Char Structure Are Found in The

Total Page:16

File Type:pdf, Size:1020Kb

1. Class String and the Char Structure Are Found in The

Full file at http://testbank360.eu/test-bank-visual-basic-2005-how-to-program-3rd-edition-harvey

16.1 Introduction

1. Class String and the Char structure are found in the: a) System.Strings namespace b) System.Chars Namespace c) System.Text namespace d) System namespace Ans: d

2. Which of the following cannot be used to form a word? a) String b) StringBuilder c) Regex d) An array of Chars e) None of the above Ans: e

3. The techniques presented in this chapter can be employed to develop: a) text editors b) word processors c) page-layout software d) All of the above Ans: d

4. The Regex and Match classes are found in the System.Text namespace. Ans: False. They are found in the System.Text.RegularExpressions namespace

5. Programmers could find patterns in a string through the classes Regex and Match. Ans: True.

16.2 Fundamentals of Characters and Strings

1. A string literal is a: a) only contains one character. b) contains numbers rather than letters. c) sequence of characters in double quotation marks. d) contains exactly its variable name and nothing else. Ans: c

2. The Unicode character set is called the: a) Constant character set b) International character set c) ASCII character set Full file at http://testbank360.eu/test-bank-visual-basic-2005-how-to-program-3rd-edition-harvey d) Special character set Ans: b

3. Characters can be: a) uppercase letters b) lowercase letters c) digits d) All of the above Ans: d

4. In the declaration: Dim color As String = "blue" a) the String literal color is assigned to the String reference "blue" b) the String reference color is assigned to the String literal "blue" c) the String literal "blue" is assigned to the String reference color d) None of the above Ans: c

5. Characters consist of the capital and lowercase alphabet. Ans: False, a character is anything within ASCII. It includes numbers and special char- acters such as +, %, and ?.

6. A string is a composition of characters used as one object. Ans: True

7. The Unicode character set has the same characters as ASCII. Ans: False, it is international and contains many more characters than ASCII.

8. When there is more than one string literal per program, the CLR will converge them all into one string with reference to the needed places in order to save memory. Ans: True

9. Characters are the fundamental building blocks of Visual Basic program source code. Ans: True.

10. Program source code is not composed of characters. Ans: False. Program source code is composed of characters.

11. A string is a series of characters treated as a single unit. Ans: True.

12. A sequence of characters in double quotation marks is often called a String reference. Ans: False. A sequence of characters in double quotation marks is often called a literal String object.

13. A character constant is an integer value that represents a character. Full file at http://testbank360.eu/test-bank-visual-basic-2005-how-to-program-3rd-edition-harvey

Ans: True.

16.3 String Constructors

1. When creating a string object, if a character array is passed as well as two integers, then the created string equals: a) the array from the first value for as many characters as the second value b) the array from the first value to the second value c) everything except from the first value to the second value d) there is no such constructor Ans: a

2. If an integer argument goes beyond the bounds of the array then: a) an ArgumentOutOfBoundsException is thrown b) a BoundsException is throw c) an ArgumentOutOfRangeException is throw d) a RangeException is thrown Ans: c

3. Visual Studio .NET treats ______as delimiters for Strings and does not treat them as part of a String. a) single quotes b) double quotes c) parentheses d) None of the above Ans: b

4. There are eight different String constructors. Ans: True

4. When using the string constructor (Char, Integer), the character is repeated in a string as many times as the integer sent is. Ans: True

5. Strings are not able to be made from an array of characters. Ans: False, if an array of characters is sent to the constructor, a string will be created and initialized with the contents of the array.

6. When dealing with a String constructor that takes a character array and a two integers the first integer denotes the start index in the array from which to begin creating the string. Ans: True Full file at http://testbank360.eu/test-bank-visual-basic-2005-how-to-program-3rd-edition-harvey

7. When dealing with a String constructor that takes a character array and a two integers the second integer specifies the last index in the array which should be part of the new string. Ans: False, it denotes the number of characters to copy from the array starting at the start index (specified by the first integer).

8. The expression New String("C"c, 5) creates a string with the value: "CCCCC". Ans: True.

9. The expression New String("America", 4, 2) creates a string with the value: "meri". Ans: False. The expression New String("America", 4, 2) creates a string with the value: "ri".

10. Immutable means that a String’s character contents cannot be changed after it is created. Ans: True.

16.4 String Indexer, Length Property, and CopyTo Method

1. The bounds on a String are always: a) 0 to string.Length. b) 1 to string.Length. c) 0 to string.Length - 1. d) 1 to string.Length - 1. Ans: c

2. String indexers treat strings as: a) binary code b) ASCII code c) arrays of characters d) a character Ans: c

3. The String method CopyTo copies a specified number of characters from a: a) Char array into a String b) String into a Char array c) String into a Integer array d) All of the above Ans: b Full file at http://testbank360.eu/test-bank-visual-basic-2005-how-to-program-3rd-edition-harvey

4. Although the programmer can go from a character array to String, there is no given way of going from a String to a character array. Ans: False, the CopyTo method of class Array allows the programmer to do so.

5. To obtain a single character from a string it can be treated as though it was an array. Ans: True

6. The Length property will return the length of a String. Ans: True

7. Strings always know their size. Ans: True

8. When a number is passed as an argument for a String indexer it returns that many characters starting from the first. Ans: False, it returns the character at that location.

9. Given the literal String object string1 = "hello there" one would be correct in assuming that string1.Length = 10. Ans: False. Given the literal String object string1 = "hello there" one would be correct in assuming that string1.Length = 11.

10. Passing an index greater than one, but less than or equal to the length of the String to Chars will result in an IndexOutOfRangeException. Ans: False. Passing an index less than zero or greater than or equal to the length of the String to Chars will result in an IndexOutOfRangeException.

11. The first argument given to method CopyTo is the character array into which the characters are copied. Ans: False. The first argument given to method CopyTo is the index from which the method begins copying characters in the String.

16.5 Comparing Strings

1. The way to find out if two Strings are equal is: a) the Equals method b) the CompareTo method c) the == operator d) All of the above Ans: d

2. When comparing “a” to “_” the correct result would be: a) “a” is greater Full file at http://testbank360.eu/test-bank-visual-basic-2005-how-to-program-3rd-edition-harvey b) they are equal c) “_” is greater d) there is no way to compare “_” to “a” Ans: c

3. The Equals method is used to see if: a) two Strings are exactly the same. b) two Strings start with the same letter. c) the ASCII sum of both Strings are the same. d) the two Strings have the same letter in the same position anywhere in the strings. Ans: a

4. String is less than another String if it comes before it alphabetically. Ans: True

5. The letter “Z” is greater than the latter “b”. Ans: False, capital letters are less than lower case letters.

6. The CompareTo method returns a 1 if the first string is less than the second, a -1 is the first string is greater and a 0 if they are the same. Ans: True

7. The StartsWith and EndsWith methods see if a string starts or ends with the given character or string. Ans: True

8. Lexicographical comparison refers to the comparison of two Strings based on their characters’ Unicode values. Ans: True.

9. A comparison of the String "hello" with the String "HELLO", using Method Equals, would return True. Ans: False. A comparison of the String "hello" with the String "HELLO", using Method Equals, would return False.

10. Method StartsWith determines if a String instance starts with the String text passed to it as an argument. Ans: True.

11. Method StartsWith only takes two arguments. Ans: False. Method StartsWith only takes one argument.

12. A lexicographical comparison of two Strings compares the integer Unicode values that represent each character in each String. Full file at http://testbank360.eu/test-bank-visual-basic-2005-how-to-program-3rd-edition-harvey

Ans: True.

16.6 Locating Characters and Substrings in Strings

1. When using the LastIndexOf method with three arguments, the second parameter must always be: a) greater than the first b) greater than the third c) equal to the first d) greater than or equal to the third Ans: d

2. If an IndexOfAny method is passed an array of characters it: a) finds the first occurrence of each letter in the String b) searches for the first occurrence of any of the characters in the String c) will search for the first occurrence of the sequence of characters d) generates an error Ans: b

3. If an IndexOfAny method is passed a string it: a) finds the first occurrence of each letter in the string b) searches for the first occurrence of any of the characters in the string c) will search for the first occurrence of the sequence of characters d) generates an error Ans: d

4. Which of the following is not a String method: a) IndexOf b) IndexOfAll c) IndexOfAny d) LastIndexOfAny Ans: b

5. The IndexOf method will return the indices of all occurrences of the given string. Ans: False, only the first instance that it comes across will be returned.

6. Method LastIndexOf is used to find the last occurrence of given text in a string. Ans: True

7. The LastIndexOfAny method scans through the array of characters backwards. Ans: True

8. String method IndexOfAny returns ElementNotFoundException when the argument is not found within the String. Full file at http://testbank360.eu/test-bank-visual-basic-2005-how-to-program-3rd-edition-harvey

Ans: False. String method IndexOfAny returns a -1 if the argument is not found within the String.

16.7 Extracting from Strings

1. When a programmer passes two integers as an argument for the Substring method: a) returns the characters from the first integer to the second b) returns as many characters as the second integer starting at the first integer c) returns as many characters as the first integer starting at the second integer d) generates an error Ans: b

2. What does the following code print out? dim example As String = “VB_Programming” Console.Write(example.Substring( 3, 5 ) a) _Pr b) _Prog c) Pro d) Progr Ans: d

3. Class String provides two Substring methods, which are used to create a new String object by part of an existing String object. a) taking b) referencing c) copying d) None of the above Ans: c

4. If a Substring method is only passed one argument then that argument must specify: a) the starting index from which the method copies b) the ending index to which the method copies c) the number of copies the method will output d) the the length of the substring to be copied Ans: a

5. There are two substring methods that can return some of the characters of one string as an individual string. Ans: True

6. If a method’s arguments cause it to access an index of the String that is beyond its length, the program will retrieve whatever is in that memory location. Ans: False, the computer will throw an ArgumentOutOfRangeException. Full file at http://testbank360.eu/test-bank-visual-basic-2005-how-to-program-3rd-edition-harvey

7. Each Substring method returns a new String object. Ans: True.

16.8 Concatenating Strings

1. Concatenating with Strings are done with: a) reserved words. b) method calls. c) operator overloading. d) operator overloading and method calls. Ans: d

2. Use the snippet of code for the following question: 1. Dim example As String = “Deitel” 2. example &= “ Books” a) This will produce an error b) This will not produce an error; however, line 2 will not change the String example. c) This will not produce an error, and the String’s value is “DeitelBooks”. d) This will not produce an error, and the String’s value is “Deitel Books”. Ans: d

3. The concatenating of two Strings is the merging of the two Strings into another String. Ans: True

4. In order to concatenate a String with another String a programmer can use the Concat method. Ans: True.

5. Another way to concatenate a String is to use the plus sign (+). Ans: False, the correct symbol is the ampersand character (&).

6. The & operator is the only way to perform String concatenation. Ans: False. The & operator is not the only way to perform String concatenation.

7. Method Concat is not a shared method. Ans: False. Method Concat is a shared method.

8. String.Concat(string1, string2) has the same result as string1 & string2. Ans: True. Full file at http://testbank360.eu/test-bank-visual-basic-2005-how-to-program-3rd-edition-harvey

16.9 Miscellaneous String Methods

1. ToUpper( string ) is a) a way of converting a String to all upper cases. b) a way to make the first letter of every word in a String a capital letter. c) a way of making one String more important than the rest. d) a syntax error. Ans: d

2. The proper way to convert a string to all lowercase is: a) STRING = string b) ToLower( string ) c) string.ToLower() d) string.ToLower( string ) Ans: c

3. Which of the following String methods does not modify the original String. a) Method Replace b) Method ToUpper c) Method ToLower d) All of the above Ans: d

4. Method ToString is not a member of class: a) String b) Object c) StringBuilder d) None of the above Ans: d

5. Method Replace of class String takes arguments. a) 4 b) 3 c) 2 d) 1 Ans: c

3. The ToUpper and ToLower methods can be used to convert a String to all upper or lower case letters, respectively. Ans: True

4. Method Replace can be used to change all occurrences of a desired character to another character. Ans: True Full file at http://testbank360.eu/test-bank-visual-basic-2005-how-to-program-3rd-edition-harvey

5. When passed a white space, method Trim can be used to eliminate all characters from a String. Ans: False, it can only be used to remove the white spaces.

6. When the Trim method is passed a character array it returns a string without any of the characters found within that array. Ans: True

7. When using the Replace method, the first character passed in is the letter to be replaced and the second is what it will be replaced by. Ans: True

8. String method Replace returns a new String after it replaces every occurrence of the second argument with the first argument. Ans: False. String method Replace returns a new String after it replaces every occurrence of the first argument with the second argument.

16.10 Class StringBuilder

1. If two StringBuilder objects contain the same string, then a) they represent the same location in memory b) they are two different objects c) if one changes, so will the other d) None of the above Ans: b

2. String objects are ______and StringBuilders are ______. a) immutable, immutable b) immutable, mutable c) mutable, immutable d) mutable, mutable Ans: b

3. Class StringBuilder is used to: a) create Strings b) manipulate Strings c) modify Strings d) All of the above Ans: d

4. Strings cannot be changed. Ans: True. Full file at http://testbank360.eu/test-bank-visual-basic-2005-how-to-program-3rd-edition-harvey

5. Each StringBuilder has a limit of characters that cannot be exceeded. Ans: False, if the limit of the StringBuilder is reached then it will grow appropriately.

6. The ToString method is used to convert a StringBuilder into a string. Ans: True

7. A String object’s contents can never change. Ans: True.

8. When appropriate, using String objects instead of StringBuilder objects improves performance. Ans: True

16.11 Length and Capacity Properties, EnsureCapacity Method and Indexer of Class StringBuilder

1. In order to set a string to reference nothing the programmer must use: a) string1 = Nothing b) string1 = "" c) string1 = EOF d) string1 = ‘’ Ans: a

2. After method EnsureCapacity doubles the StringBuilder instance’s current capacity, if the new capacity is still lower than the value that the programmer wishes to ensure: a) EnsureCapacity doubles capacity again b) EnsureCapacity sets capacity to the requested number c) EnsureCapacity sets capacity to one more than the requested number d) None of the above Ans: c

3. Method EnsureCapacity is used to return the capacity of a StringBuilder. Ans: False, EnsureCapacity is used to ensure that the capacity is at least a minimum value.

4. Properties Length and Capacity are used to return the number of characters in the StringBuilder and the total length allowed (at that time) of the StringBuilder. Ans: True

5. Exceeding the capacity of a StringBuilder causes the program to throw a OutOfRangeException. Full file at http://testbank360.eu/test-bank-visual-basic-2005-how-to-program-3rd-edition-harvey

Ans: False. Exceeding the capacity of a StringBuilder causes the capacity to expand to accommodate the additional characters.

6. Every StringBuilder can store a certain number of characters that is specified by its capacity. Ans: True.

7. Method EnsureCapacity allows programmers to guarantee that a String- Builder has a capacity that reduces the number of times the capacity must be increased. Ans: True.

8. The keyword Nothing is the same thing as the empty String, "". Ans: False. The keyword Nothing is a null reference and is not the same thing as the empty String, "".

16.12 Append and AppendFormat Methods of Class StringBuilder

1. Method AppendFormat allows: a) numbers to be inserted in Strings. b) some formatting to be made to the String. c) anything added to a String. d) one String to be added to another. Ans: b

2. If a number is formatted with the D3 formatter, it means that: a) the number has to have at least 3 digits even if they are zero b) the number has a dollar sign and is at least 3 digits long c) creates each number in 3 dimensions d) it is an error Ans: a

3. A format string has the form: a){X[:FormatString][,Y]} b){X[,Y][:FormatString]} c){[FormatString:]X[,Y]} d) None of the above Ans: b

4. Method Append is used to add the String representation of various data type values to the end of a StringBuilder. Ans: True Full file at http://testbank360.eu/test-bank-visual-basic-2005-how-to-program-3rd-edition-harvey

5. Method Append can only be use on the primitive data types. Ans: False, it can also be used on character arrays, strings, and objects.

6. Method AppendFormat can be used to format objects with spaces or using proper mathematical notations Ans: True

7. StringBuilder method Append, which takes a String, behaves similarly to the String’s & operator. Ans: False. StringBuilder method Append modifies a StringBuilder object by adding the specified String to StringBuilder’s internal String representation. String’s & operator creates a new String by concatenating two Strings. The & operator does not modify the original two Strings.

8. In a FormatString a positive optional argument after a comma aligns the string to the left, a negative one aligns it to the right. Ans: False. In a FormatString a positive optional argument after a comma aligns the string to the right; a negative one aligns it to the left.

9. Method Append allows various data-type values to be added to the end of a StringBuilder. Ans: True.

16.13 Insert, Remove and Replace Methods of Class StringBuilder

1. If a Replace method is passed ( “M”c, “m”c, 0, 3 ) it will: a) replace any character “M” with “m” in the first 3 characters b) replace any letter “M” with “m” in the first 4 characters c) replace the first letter “M” with “m” in the first 3 characters d) replace the first letter ’M’ with “m” in the first 4 characters Ans: a

2. Which is not a StringBuilder method? a) Insert b) Add c) Replace d) ReplaceAll e) b and d Ans: e

3. If method Replace has four arguments then the third argument must be: Full file at http://testbank360.eu/test-bank-visual-basic-2005-how-to-program-3rd-edition-harvey a) the character to be replaced b) the new character c) the index at which to begin d) the count Ans: c

4. Method Insert can be used to insert various data types into a given position of a StringBuilder. Ans: True

5. Method Insert can only be used on the primitive data types. Ans: False, just like method Append, Insert can also be used on character arrays, strings, and objects.

6. Method Remove can be used to delete any part of a StringBuilder. Ans: True

7. Replace is a method that allows the user to change any character in a StringBuilder to the given argument. Ans: True

16.14 Char Methods

1. The IsPunctuation method will return true if: a) if it is a period (.) or a comma (,) b) if it is a period (.), a comma (,), a !, a ?, a colon (:), or a semicolon (;) c) if it is all of b) including all the braces ( (, {, and [ ) d) anything that is not a letter or a white space Ans: b

2. An example of a structure is: a) an Integer b) a Double c) a Char d) a Byte e) All of the above Ans: e

3. A structure in Visual Basic is similar to: a) an object b) a class c) a String d) None of the above Ans: b Full file at http://testbank360.eu/test-bank-visual-basic-2005-how-to-program-3rd-edition-harvey

4. Structures are created using the keyword: a) Class b) Structure c) Sub d) None of the above Ans: b

5. Structures are like classes in that they encapsulate reference types. Ans: False, while classes do encapsulate reference types, structures encapsulate value types.

4. There are many character methods some of which are capable of determining whether a character is a letter, a digit, a symbol, or a punctuation. Ans: True

6. The method IsWhiteSpace is only used to determine whether a character is a space or not. Ans: False, white spaces also include tabs and newlines.

7. Both structures and classes use the same modifiers such as Public, Private and Protected. Ans: True.

8. Although structures and classes are comparable in many ways, structures do not encapsulate value types. Ans: False. Although structures and classes are comparable in many ways, structures en- capsulate value types.

16.15 Card Shuffling and Dealing Simulation

1. Properties of controls need to be set at design time. Ans: False, the properties can be changed at runtime using the dot operator (.).

16.16 Regular Expressions and Class Regex

1. When a quantifier is greedy it: a) will return a random number, more than one, of results b) returns half the results c) returns each result in alphabetical order d) returns as many results as possible Ans: d

2. To make a quantifier lazy use: Full file at http://testbank360.eu/test-bank-visual-basic-2005-how-to-program-3rd-edition-harvey a) a ? before it b) a ? after it c) a % before it d) a % after it Ans: b

3. If a programmer desires to use an asterisk (*) literally in a regular expression, they use: a) "*" b) "/*" c) "\*" d) "_*" Ans: c

4. The difference between {n} and {n,} is: a) {n} matches at least n occurrences b) {n} matches exactly n occurrences c) {n,} matches exactly n occurrences d) {n,} generates a syntax error Ans: b

5. To make a search return between 10 and 20 results use a) { 10, 20 } b) ( 10, 20 ) c) [ 10, 20 ] d) < 10, 20 > Ans: a

5. The String Split method is used to: a) break a String into a character array b) divide a String in half c) break a String into individual characters d) break a String into substrings, such that the substrings appear in the original String and are separated by at least one of the characters supplied Ans: d

6. Method Matches can be used to get a list of all matches with a character. Ans: True

7. Method Match will only return a single match with a character. Ans: True

8. In regular expressions, a word character is considered to be any alphanumeric character. Ans: False the underscore (_) is also included. Full file at http://testbank360.eu/test-bank-visual-basic-2005-how-to-program-3rd-edition-harvey

9. The asterisk (*) can be used to match an expression zero or more times. Ans: True

10. The (+) character performs the same function as the asterisk (*). Ans: False, + matches an expression one or more times, while * matches an expression zero or more times.

11. A lazy quantifier will return only the first case that matches the specifications. Ans: True

12. By default all quantifiers are lazy. Ans: False, they are greedy.

13. Regular expressions can be useful during information validation, for which data must be a particular data type. Ans: False. Regular expressions can be useful during information validation, for which data must be in a particular format.

14. One application of regular expressions is to facilitate the construction of a compiler. Ans: True.

Recommended publications