Professional Documents
Culture Documents
Textbook The Last Operators of String Type: Null or Empty Method
Textbook The Last Operators of String Type: Null or Empty Method
Textbook The Last Operators of String Type: Null or Empty Method
Chapter 14
The last operators of String type
Comparison operator
{
string a="ZU-047";
string b="ZU-047";
//Console.WriteLine(a==b);
Console.WriteLine(a.Equals(b));
Console.WriteLine(a.Equals("047"));
Console.ReadKey();
}
Result is
True
False
If there is no any “computer” word in your entered sentence, then for conclusion index will be
equal to “-1” and because of this line
***Console.WriteLine(str.Remove(index+8,str.Length-index-8));***
Index+8 will be “-1+8=7”. So from 7th symbol our all symbols will erase from the text.
Write a program that removes all symbols before and after “computer” word.
{
string str;
Console.WriteLine("Enter sentence whatever you want");
str = Convert.ToString(Console.ReadLine());
int index = str.IndexOf("computer");
str = str.Remove(index + 8, str.Length - index - 8);
str = str.Remove(0, index);
Console.WriteLine(str);
Console.ReadKey();
}