C# Strings and Text Processing

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Are the following? What will the outputs be? string result = "Hello, reader! " result = result + "How are you? result += "How are you?"

They will be the same, the output will be: Hello, reader! How are you?

Where are the values of a string stored and what do the variables contain?

Values stored in the dynamic memory (managed heap) and variables contain a reference to an object in the heap.

What is the symbol for the indexer operator

[ ]

What is instantiating?

a process associate with the allocation of the dynamic memory area (the heap)

StringBuilder method Append(...)

appends string, number, or other value after the last character in the buffer

What would be the value of boolValue after the following initialization?: string text = "True"; bool boolValue = bool.Parse(text);

boolValue = true for parsing to a bool, casing doesn't matter.

What does Substring(startInex, length) do?

extracts a substring from a string, which is located between startIndex and (startIndex + length - 1) inclusively.

StringBuilder method Insert(int offset, string str)

inserts a string in a given start position (offset)

What does CompareTo(...) return and in what cases?

negative value, zero, or a positive value depending on the lexical order of the two compared strings... a negative value means that the first string is lexicographically before the second... so on.

StringBuilder method Remove(int startIndex, int length)

removes (deletes) string from the buffer with a given start position and length

StringBuilder method Replace(string oldValue, string newValue)

replaces all occurrences of a given substring with another substring

StringBuilder method Length

returns length of string saved in the variable number of used positions in the buffer)

StringBuilder method ToString()

returns the StringBuilder object content as a string object

StringBuilder method Capacity

returns the buffer size (total number of used and unused positions in the buffer)

The index of the first char in string a = "dfads";

the index is 0 and it contains the char 'd'

String.Format(...)

A static method by which you can format text and other data through a template.

What happens if you try to manipulate a string with the value null?

An error will be generator (the exception for access to a missing value is NullReferenceException)

What is the initial value for a string and why?

null, because a variable of a string type is handled as an object

StringBuilder method Clear(...)

removes all characters from the buffer (deletes it)

Indexer [int index] in StringBuilder

returns the character stored in a given position

What is a String?

A sequence of characters stored in a certain address in memory. i.e. an array of characters

Does string concatenation change the existing strings?

No

What does it mean to set a string literal?

To assign a predefined textual content to a variable of type string

What are the backslashes used for in the following string initialization? string quote = "Book's title is \"Johnny Appleseed\"";

To indicate that the quotes are not being used to start or end a string but are part of the data.

What id data parsing?

To obtain a value of a given type from the text representation of this value in a specific format... i.e. converting from text to some other data type.

The Lexicographical comparison does not follow the letter arrangement in the Unicode table (true or false)

True

What is normally the most convenient way to check for string equality? and what does it return?

.Equals(...); returns a boolean

What is StringBuilder and what does it overcome?

A class that serves to build and change strings. It overcomes the performance problems that arise when concatenating strings of type string.

Describe StringComparison.CurrentCultureIgnoreCase

A constant of the enumerated type StringComparison... can be used as a parameter of .Equals() to ignore case (capital or lower) when comparing two strings

What does the CompareTo(...) method allow you to do?

Allows you compare the values of two strings in order to determine the lexicographical order.

What is a buffer?

An area of memory which is allocated and used only temporarily.

What can Trim(...) accept as a parameter?

An array of characters that you want to remove from a string.

Is string concatenation exclusive to strings? Or can we combine other data types?

Any data, which can be presented in a text form, can be appended to a string.

Why is it generally a bad idea to perform string concatenation in a loop?

Can lead to extreme performance problems

StringBuilder(int capacity)

Constructor with an initial capacity parameter. It may be used to set the buffer size in advance.

Escaping

Displaying special characters in the source code

What does the method Trim(...); do?

Eliminates the white spaces at the beginning or at the end of a string. The whitespaces include: spaces, tabs, line breaks, etc.

What are two methods used to search within a string for another string?

IndexOf(...) and LastIndexOf(...)

What is the major difference between IndexOf(...) and LastIndexOf(...)? (Non-overloaded... most basic difference)

IndexOf(...) starts searching the contents of a text sequence from the beginning of the string while LastIndexOf(...) starts searching from the end of a string towards the start.

What is another name for creating a variable of a certain class?

Instantiating

Regular expressions have what benefit?

Make text processing easier and more accurate.

What is special about the method ToString(...) in C#?

Practically every object of a class and primitive variables can be presented as text...It is implicit in the definition of the object class which is the base class that all .NET data types inherit directly or indirectly.

What does Split(...) allow you to do?

Split a string by a separator

What do String.Format(...) templates contain and what are they used for?

Text and declared parameters (placeholders) and are used to obtain fomatted text after replacing the parameters with specific values.

The keyword "string" is an alias for what?

The System.String class from the .NET Framework

What does it mean to say that a string is immutable?

The content of the variable does not change directly - if you attempt to change the value, it will be saved to a new location in the dynamic memory and the variable will point to it.

What is the garbage collector (memory cleaning system) responsible for?

The disposing of objects in dynamic memory when they are no longer used.


Kaugnay na mga set ng pag-aaral

Motor Controls - Ch 5 - Electric Motors

View Set

Ch 17 Program Design for Resistance Training

View Set

Echolalia csd 626-autism [midterm]

View Set

Possible Conceptual questions mostly on Risk and Bonds

View Set

The Memory Game ABCDEFGHIJKLMNOPWRSTUVWXYZ The numbers 1 through 10000 ## [1] 1 2 3 4 5 6 7 8 9 10 11 ## [12] 12 13 14 15 16 17 18 19 20 21 22 ## [23] 23 24 25 26 27 28 29 30 31 32 33 ## [34] 34 35 36 37 38 3

View Set

B&G Chapter 2 Parts I and II Review Questions

View Set