Test Bank Answers Text Processing Chapter 8 - Test Bank | Visual C# 5e by Tony Gaddis. DOCX document preview.
Starting Out with Visual C#, 5e (Tony Gaddis)
Chapter 8 Text Processing
TRUE/FALSE
1. A variable of the char data type can hold up to 256 characters at a time.
2. Because char variables can hold only one character, they are not assignment-compatible with string variables.
3. The char data type provides a single method that determines whether a character is a letter or a number.
4. You can use a subscript expression such as name[3] = 'A' to change the value of a character within a string.
5. If you pass an uppercase letter to the char.ToLower method, the character it returns will be unchanged.
6. Character testing methods, such as char.IsLetter, return a Boolean value of true or false.
7. The Substring method returns a string.
8. Methods for modifying strings do not actually modify the calling string object but they return a modified copy of the calling string object.
9. When you call a string object's Split method, the method extracts tokens from the string and returns them as integers.
10. When you pass null as an argument to the Split method, the method tokenizes the string using the comma character as the deliminator.
11. A string object's ToUpper method converts the first character in the string to uppercae.
12. The process of breaking a string down into smaller string components is called tokenizing.
13. In C# you can only provide one delimiter per string that you wish to tokenize when calling the Split method.
14. When you tokenize a string entered by the user and the string contains characters other than white spaces as delimiters, you do not need to trim the string before tokenizing it.
15. In the following example, there are four tokens:
"milk cup cupcake cake cookie"
16. The String.Format method allows you to format and insert values into a string.
17. In the following statement, the format string is car:
string message - String.Format("I own a blue ", car);
18. In the following statement, the car variable is argument 1:
string message - String.Format("I own a blue ", car);
19. In a format item, to format an argument in a specific way, you can use a format specifier.
20. To format a number as currency you use the Curr format specifier.
21. In a format item, the minimum field width is the minimum number of spaces that should be used to display a value and if the value is too large to fit in the specified field width, the number will be truncated.
22. It is possible to specify the number of digits to display after a decimal point with a numeric format specifier.
23. If you specify a field width of 15 spaces but the number to be displayed only uses 10 spaces, the number will be left-justified.
24. If you want a number to be left-justified within its field, you insert a minus sign (-) before the field width specifier.
25. If the N2 format specifier is used on the number 5.378, the resulting value will be 5.37.
MULTIPLE CHOICE
1. In C# __________ literals are enclosed in single quotation marks.
a. | character | b. | numeric | c. | string | d. | Boolean |
2. The __________ data type is used to store individual characters.
a. | bool | b. | string | c. | char | d. | int |
3. To convert a char variable to a string, call its __________ method.
a. | CompareTo | c. | Equals |
b. | ToString | d. | GetType |
4. C# allows you to access the individual characters in a string using __________.
a. | switch statements | c. | named constants |
b. | subscript notation | d. | character literals |
5. Subscript notation provides __________ access to individual characters in a string.
a. | write-only | b. | local | c. | read-only | d. | global |
6. Given the code sample shown, which of the following values is stored in the letter variable?
string tree = "Pear";
char letter = tree[3]
a. | P | b. | e | c. | a | d. | r |
7. Which of the following character testing methods would you use to determine if a character is a number in the range 0 through 9?
a. | char.IsDigit | c. | char.IsPunctuation |
b. | char.IsLower | d. | char.IsWhiteSpace |
8. Which of the following character testing methods would you use to verify whether or not a password contains spaces?
a. | char.IsLetterOrDigit | c. | char.IsPunctuation |
b. | char.IsLower | d. | char.IsWhiteSpace |
9. Which of the following character testing methods would you use to determine if a sentence contains capital letters?
a. | char.IsNotLower | c. | char.IsPunctuation |
b. | char.IsUpper | d. | char.IsWhiteSpace |
10. The __________ method returns the lowercase equivalent of a character.
a. | char.IsLower | c. | this.Lowercase |
b. | char.ToLower | d. | this.char.Convert |
11. A string object's __________ method returns true if the substring being searched for is contained within the string; otherwise it returns false.
a. | Contains | b. | Substring | c. | IndexOf | d. | Insert |
12. The __________ method returns true if the string object starts with the substring being searched for or otherwise it returns false.
a. | Contains | c. | StartsWith |
b. | TrimStart | d. | IndexOf |
13. The __________ method returns true if a string object ends with a specific substring value or otherwise it returns false.
a. | LastIndexOf | c. | TrimEnd |
b. | Substring | d. | EndsWith |
14. A string within a string is called a __________.
a. | thread | b. | nested string | c. | strand | d. | substring |
15. The __________ methods return an integer value indicating the starting position of a substring within a string object.
a. | IndexOf and LastIndexOf |
b. | Insert and Remove |
c. | ToUpper and ToLower |
d. | Substring and Trim |
16. The __________ method can be used to retrieve a specific set of characters from a string.
a. | Insert | b. | Substring | c. | Trim | d. | Copy |
17. __________ are spaces that appear at the beginning of a string.
a. | Leading spaces | c. | Indentations |
b. | Empty spaces | d. | Tabbed spaces |
18. __________ spaces are spaces that appear at the end of a string.
a. | Hanging | b. | Trailing | c. | Padded | d. | Suffix |
19. The __________ method places a string inside another string.
a. | Remove | b. | Trim | c. | Insert | d. | Substring |
20. The __________ method removes specified characters from a string.
a. | Remove | b. | Delete | c. | Extract | d. | TrimEnd |
21. The __________ method removes all leading and trailing spaces from a string.
a. | Remove | c. | Trim |
b. | NoSpaces | d. | RemoveSpace |
22. In programming terms, __________ are a series of words or other items of data contained in a string that are separated by spaces, commas, or other characters.
a. | tokens | b. | lexicons | c. | delimiters | d. | key values |
23. The character that separates tokens is known as a(n) __________.
a. | sentinel | b. | article | c. | delimiter | d. | separator |
24. The process of dividing a string into tokens is known as __________.
a. | parsing | b. | tokenizing | c. | object splitting | d. | threading |
25. In C#, string objects have a method named __________ that is used to tokenize strings.
a. | Tokenize | b. | Delimit | c. | Break | d. | Split |
26. Before tokenizing a string you should use the __________ method to remove leading and/or trailing whitespace characters to prevent them from being included in the first and last tokens.
a. | Trim | b. | Remove | c. | Split | d. | Substring |
27. The __________ method allows you to format and insert values into a string.
a. | Format | c. | Format.String |
b. | InsertString | d. | String.Format |
28. What will be the output of the following code sample?
string color2 = "blue";
string color1 = "green";
string message = String.Format("We offer this shirt in {0} and {1} colors.", color1, color2)
a. | We offer this shirt in blue and green colors. |
b. | We offer this shirt in green and blue colors. |
c. | We offer this shirt in 0 and 1 colors. |
d. | None of the above. |
29. In the following code, what is the argument 1 variable?
string color1 = "blue";
string color2 = "green";
string message = String.Format("We offer this shirt in {0} and {1} colors.", color1, color2)
a. | color1 | b. | color2 | c. | "blue" | d. | "green" |
30. Given the following code sample, what will be displayed?
decimal money = 453.29334m;
string message = String.Format("Paycheck: {0:C}", money);
a. | Paycheck: $453.29334 | c. | Paycheck: 453.29334 |
b. | Paycheck: $453.29 | d. | Paycheck: 453.29 |
31. Given the following code sample, what will be displayed?
double number = 152.4562701;
string message = String.Format("The number is {0:N4}", number);
a. | The number is 152.4563 | c. | The number is 152.5 |
b. | The number is 152.4562 | d. | The number is 0.4563 |
32. What is the minimum field width in the following code sample?
double number = 23.9828;
string message = String.Format("The number is {0, 12}", number);
a. | 12 spaces | c. | 23spaces |
b. | 8 spaces | d. | It is impossible to tell from this code. |
33. The __________ format specifier causes a number to be multiplied by 100 and displayed with a trailing space and a percent sign (%).
a. | N | b. | E | c. | P | d. | F |
34. Which of the following format specifiers will display the number 2345.0 as 2345.00?
a. | N3 | b. | E3 | c. | P | d. | F2 |