DEV Community

Sanjar Rashidov
Sanjar Rashidov

Posted on • Edited on

1 1 2 2 1

C# da string metodlari

C# dasturlash tilida har xil String metodlari mavjud.

1.Substring -> string qaytardi va 2 ta integer qabul qiladi. 1-integer qayerdan boshlab olinishi kerakligi uchun kerak(indeks orqali). 2-integer (ixtiyoriy) va u nechta character olish kerakligini belgilaydi.

string message = "Welcome to .Net class";
string part = message.Substring(11, 4);
Console.WriteLine(part);
Enter fullscreen mode Exit fullscreen mode

2.Replace -> 2 ta string qabul qiladi. Agarda o'zgartirish kerak bo'lgan belgilarni topa olmasa, original string ni o'zgaruvchiga saqlaydi.

string message = "Welcome to .Net course";
string replacedString = message.Replace(".Net", "English");
Console.WriteLine(replacedString);
Enter fullscreen mode Exit fullscreen mode

3.Compare -> 2 ta string qabul qiladi. 1-stringga qarab, 2-stringni tekshiradi. Return type integer.

int result = string.Compare("apple", "Apple");
Console.WriteLine(result);
Enter fullscreen mode Exit fullscreen mode

4.Contains -> bool qaytaradi(true/false). Bir dona tekshiriladigan string qabul qiladi.

string message = "Welcome to .NET course";
string course = ".NET";
bool hasDotNet = message.Contains(course);
Console.WriteLine(hasDotNet);
Enter fullscreen mode Exit fullscreen mode

5.Trim -> yangilangan string qaytaradi. Bo'sh joylarni (Space) boshidan va oxiridan olib tashlaydi.

string name2 = "                Rashidov Sanjar            ";
string updatedname = name2.Trim();
Console.WriteLine(name2);
Enter fullscreen mode Exit fullscreen mode

6.Index -> qidirish uchun string qabul qiladi. Return type integer.

string text = "Hello World!";
int index = text.IndexOf("o");
Enter fullscreen mode Exit fullscreen mode

7.Verbatim -> biror tekst yoki so'zni o'zgartirishlarsiz chop etish uchun foydalanashimiz mumkin. Verbatimni ifodalash uchun "@" belgisidan foydalanamiz.

Console.WriteLine("C:\\Windows\\System32\\calc.exe");
Console.WriteLine(@"C:\\Windows\\System32\\calc.exe");
Console.WriteLine("C:\nWindows\nSystem32\ncalc.exe");
Console.WriteLine(@"C:\nWindows\nSystem32\ncalc.exe");
Enter fullscreen mode Exit fullscreen mode

8.Split -> string ajratgichlari orqali bolaklarga bo'lib beradi, ya'ni alohida qilib ajratadi.

string originalString = "olma,anor,banan";
string mevalar = originalString.Split(',');
Console.WriteLine(mevalar[0]);
Console.WriteLine(mevalar[1]);
Console.WriteLine(mevalar[2]);
Enter fullscreen mode Exit fullscreen mode

9.Join -> stringlarni qoshib chiqarish uchun ishlatiladi. Return type string.

string[] words = {"Salom", "Ilmhub", "Megaschool"};
string joinedText = string.Join(", ", words);
Console.WriteLine(joinedText);
Enter fullscreen mode Exit fullscreen mode

10.Remove -> 2 ta integer ya'ni 1-integer(indeks) qayerda boshlanishi, 2-integer nechta character olib tashlash kerakligini aytadi.

string message = "Welcome to English .Net course";
int indexOfDotNet = message.IndexOf(".NET");
string correctedMessage = message.Remove(indexOfDotNet, 5);
Console.WriteLine(correctedMessage); 
Enter fullscreen mode Exit fullscreen mode

11.StartsWith -> string qabul qiladi, bool qaytaradi. Agarda biz bergan so'z bilan boshlansa true, bomasa false qaytadi.

string mail = "something@gmail.ru";
bool startWith = mail.StartsWith("something");
Console.WriteLine(startWith);
Enter fullscreen mode Exit fullscreen mode

12.EndsWith -> string qabul qiladi, bool qaytaradi. Agarda biz bergan so'z bilan tugasa true, bomasa false qaytadi.

string mail = "something@gmail.ru";
bool endsWith = mail.EndsWith("mail.ru");
Console.WriteLine(endsWith);
Enter fullscreen mode Exit fullscreen mode

13.ToUpper -> string ni katta harflarga o'zgartirib beradi.

string text = "warning!";
Console.WriteLine(text.ToUpper());
Enter fullscreen mode Exit fullscreen mode

14.ToLower -> string ni kichik harflarga o'zgartirib beradi.

string text = "WARNING!";
Console.WriteLine(text.ToLower());
Enter fullscreen mode Exit fullscreen mode

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (2)

Collapse
 
muhammadyusuf_xotamo profile image
Muhammadyusuf Xotamov

maniki yaxshiro

Collapse
 
sanjar777 profile image
Sanjar Rashidov

👎🏻

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →