Archive for the ‘F- Strings’ Category

Dealing with Simple Strings

Sunday, March 8th, 2009

From before, you know how to declare a string, here it is again for you

string myString;
myString = “Hi There, i am a string”;

Parsing
Assuming your string is
string myStringInteger = “10″;

and you want to get that value in an integer variable
You can simply use the parse keyword
int myInteger = int.Parse(myStringInteger);

You can do that to a boolean variable as well
string myBoolString = “True”;
bool myBool = bool.Parse(myBoolString);

Strings come with extra functionality as well.

myBoolString.Length will be equal to 4 since True has 4 letters.

Strings are no good for efficiency, rather you would want to use StringBuilder for larger texts

You may also be interested in knowing that although a string is not a value type, the == operator is overloaded to mean “Is the content identical in both strings”, If you don’t know why this is strange, You will find out as you read