General C# programming - strings Flashcards

1
Q

How do you reverse the order of an array?

A

Array.Reverse(names); name = the name of the array.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you convert a string to a char array?

A

string hello =”hello”;

char[] chararray = hello.ToHelloArray();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you write a backslash within a string?

A

write two \

example

“go to c :\ drive”;

which will make

go to c:\ drive

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you add a quotation mark in a string?

A

Put a backslash in front of it

example:

“Hello how are "you" doing today”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you create a new line in a string?

A

add a \n

example :

“How are you \n doing today”

result:

How are you

doing today

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does the 0 and the 1 in the following string represent?

string myString = string.Format (“Make: {0} (model : {1})”, “BMW” , “760li”);

A

the {0} represents the first parameter and the {1} represents the second parameter.

so

“Make: {0} (model : {1})”, “BMW” , “760li”);

becomes

make : bmw

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you convert the 123.45 to read as $123.45 in the following string?

string myString = string.Format(“{0}”, 123.45);

A

Add :C after the 0

string myString = string.Format(“{0:C}”, 123.45);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you make the following argument in the string a percentage?

string myString = string.Format(“{0}”, .123);

A

Add :P after the 0

string myString = string.Format(“{0:P}”, .123);

will print out

12.30%

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you make this argument in the string appear as a phone number?

string myString = string.Format(“phone number :{0}”,1234567890);

A

Add a : after the 0 and for every number in the argument, add a # sign.

string myString = string.Format(“phone number :{0:(###)###-####}”,1234567890);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does Substring(5, 14); do in the following code?

string myString = “that summer we took threes across the board”;

myString = myString.Substring(5, 14);

A

The string will start at the fifth position in the string and return 14 carachters.

result = Summer we took

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do you make the following string all caps?

string myString = “that summer we took threes across the board”;

A

myString = myString.ToUpper();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly