General C# programming - strings Flashcards
How do you reverse the order of an array?
Array.Reverse(names); name = the name of the array.
How do you convert a string to a char array?
string hello =”hello”;
char[] chararray = hello.ToHelloArray();
How do you write a backslash within a string?
write two \
example
“go to c :\ drive”;
which will make
go to c:\ drive
How do you add a quotation mark in a string?
Put a backslash in front of it
example:
“Hello how are "you" doing today”
How do you create a new line in a string?
add a \n
example :
“How are you \n doing today”
result:
How are you
doing today
What does the 0 and the 1 in the following string represent?
string myString = string.Format (“Make: {0} (model : {1})”, “BMW” , “760li”);
the {0} represents the first parameter and the {1} represents the second parameter.
so
“Make: {0} (model : {1})”, “BMW” , “760li”);
becomes
make : bmw
How do you convert the 123.45 to read as $123.45 in the following string?
string myString = string.Format(“{0}”, 123.45);
Add :C after the 0
string myString = string.Format(“{0:C}”, 123.45);
How do you make the following argument in the string a percentage?
string myString = string.Format(“{0}”, .123);
Add :P after the 0
string myString = string.Format(“{0:P}”, .123);
will print out
12.30%
How do you make this argument in the string appear as a phone number?
string myString = string.Format(“phone number :{0}”,1234567890);
Add a : after the 0 and for every number in the argument, add a # sign.
string myString = string.Format(“phone number :{0:(###)###-####}”,1234567890);
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);
The string will start at the fifth position in the string and return 14 carachters.
result = Summer we took
How do you make the following string all caps?
string myString = “that summer we took threes across the board”;
myString = myString.ToUpper();