Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace DemoString
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- string name = "Desi"; //Console.Readline()
- Console.WriteLine(name[0]); //първия символ
- Console.WriteLine(name[name.Length - 1]); //последния символ
- Console.WriteLine(name.Length); //брой на символи
- char [] symbols = name.ToCharArray();// ['D', 'e', 's', 'i']
- Console.WriteLine("Desi" + "Test"); //"DesiTest"
- Console.WriteLine("Desi" + 23); //"Desi23"
- Console.WriteLine("Desi" + 2.50); //"Desi2.50"
- Console.WriteLine(1 + 1 + "Test" + 1 + 2); //"2Test21"
- Console.WriteLine(name.IndexOf('D')); // 0
- Console.WriteLine(name.IndexOf('s')); // 2
- Console.WriteLine(name.IndexOf('e')); // 1
- Console.WriteLine(name.IndexOf('p')); // -1
- string sentence = "The cat in under the table";
- string lastWord = sentence.Substring(21); //table
- Console.WriteLine(lastWord);
- string firstWord = sentence.Substring(0, 3); //The
- Console.WriteLine(firstWord);
- string[] words = sentence.Split(' '); //["The", "cat", "in", "under", "the", "table"]
- foreach(string word in words) //цикъл за обхождане на колекции (лист и масив)
- {
- Console.WriteLine(word);
- }
- sentence.Replace(' ', '_');
- Console.WriteLine(sentence); //"The_cat_in_under_the_table"
- sentence.Remove('e');
- Console.WriteLine(sentence); //"Th_cat_in_undr_th_tabl"
- Console.WriteLine(sentence.Contains('u')); //True
- Console.WriteLine(sentence.Contains('z')); //False
- // True -> ако буквата u я има в текста; False -> ако буквата u я няма в тескта
- Console.WriteLine(sentence.ToUpper()); //TH_CAT_IN_UNDR_TH_TABL
- Console.WriteLine(sentence.ToLower()); //th_cat_in_undr_th_tabl
- Console.WriteLine(sentence.StartsWith("Th")); //True
- Console.WriteLine(sentence.StartsWith("Table")); //False
- //True -> ако текстът започва с th
- //False -> ако текстът НЕ започва с th
- Console.WriteLine(sentence.EndsWith("tabl")); //True
- Console.WriteLine(sentence.EndsWith("The")); //False
- //True -> ако текстът завършва с th
- //False -> ако текстът НЕ завършва с th
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment