DEV Community

umida5
umida5

Posted on

String operations

string name = "John";
string upperName = name.ToUpper();
Console.WriteLine(upperName();

bu kodda name degan ozgaruvchini qiymatini ToUpper funkiyasi bilan hamma
harflarini katta qilib beradi.
natija: "JOHN";

1.String qiymatlarini birlashtirish uchun + operatoridan foydalanish mumkin. Bu string larni qo'shish imkonini beradi.
Shuningdek, String.Concat() metodidan ham foydalanishingiz mumkin.


string name = "Ali";
string surname = "Valiyev";
string fullName = name + " " + surname;
// Yoki
string fullNameConcat = String.Concat(name, " ", surname);
Enter fullscreen mode Exit fullscreen mode
  1. Compare: Compare metodi ikkita string ni taqqoslaydi va ularning tartibini aniqlash uchun ishlatiladi:
  2. 0 qaytarsa, ikkisi teng.
  3. Katta son qaytsa, birinchi string kattaroq.
  4. Manfiy son qaytsa, birinchi string kichikroq.

string str1 = "Apple";
string str2 = "Banana";
int result = string.Compare(str1, str2);
Console.WriteLine(result);  // -1 (Apple kichik Banana'dan)
Enter fullscreen mode Exit fullscreen mode

Top comments (0)