Format()
Stringni formatlash uchun ishlatiladi:
var testString = string.Format("Hello {0}", 123123);
Console.WriteLine("Hello {0:C}", 123123);
output:Hello 123123
Split()
Stringni substringlarga ajratadi va string array qaytaradi.
var originalString = "olma anor nok";
var mevalar = originalString.Split(' ');
Console.WriteLine(mevalar[0]);
Console.WriteLine(mevalar[1]);
Console.WriteLine(mevalar[2]);
output:
olma
anor
nok
Quyidagi hollarda **Split()** ko'p ishlatiladi:
var sum = Console.ReadLine()?
.Split(' ', StringSplitOptions.RemoveEmptyEntries)
.Select(int.Parse)
.Aggregate((x, y) => x + y);
Console.WriteLine(sum);
Istagancha sonni string ko'rinishida kiritadigan bo'lsak,uni int tipiga o'tkazib,bo'sh probellarni olib tashlab yigindisini hisoblaydi.
Bu yerda RemoveEmptyEntries funksiyasi bo'sh probellarni olib tashlash uchun ishlatilsa,TrimEmptyEntries begilarning ikkala tomonidagi ya'ni oldi va ortidagi probellarni olib tashlaydi.
Replace()
Function tekst qiymatini o'rniga yangi qiymatga o'zgartirish imkoniyatini beradi
string sayHello = "Hello world";
Console.WriteLine(sayHello);
sayHello = sayHello.Replace("Hello", "Greetings");
Console.WriteLine(sayHello);
Contains()
Stringning berilgan substringdan tashkil topgan yoki yo'qligini tekshiradi.
string songLyrics = "You say goodbye, and I say hello";
Console.WriteLine(songLyrics.Contains("goodbye"));
Console.WriteLine(songLyrics.Contains("say"));
Console.WriteLine(songLyrics.Contains("greetings"));
Trim()
Stringning oldi yoki ortidagi barcha bo'sh kataklarni o'chirish uchun ishlatiladi.
var stringWithSpaces = " hello world \n";
Console.WriteLine(stringWithSpaces);
Console.WriteLine(stringWithSpaces.Trim());
Console.WriteLine(stringWithSpaces.TrimEnd());
Console.WriteLine(stringWithSpaces.TrimStart());
EndWith()
String berilgan string bilan tugash yoki tugamasligini tekshiradi.
Console.WriteLine(songLyrics.EndsWith("hello"));
Console.WriteLine(songLyrics.EndsWith("goodbye"));
StartWith()
String berilgan string bilan boshlanishini tekshiradi.
Console.WriteLine(songLyrics.StartsWith("You"));
Console.WriteLine(songLyrics.StartsWith("goodbye"));
ToUpper()
Katta harfga aylantirib qo'yadi.
Console.WriteLine("ToUpper()");
Console.WriteLine(longString.ToUpper());
ToLower()
Kichik harfga o'zgartirib qo'yadi.
Console.WriteLine("ToLower()");
Console.WriteLine(longString.ToLower());
Top comments (3)
raxmat jigarm atdushi
Gʻazini bos gap yoʻ
гап жок йорворейшн