String

Is string literal mutable or immutable ?
Is string variable mutable or immutable ?

String literal – deb ” ” ichida constanta sifatida yozilgan stringga aytiladi.

String literal immutable – degani bu qoymatni o’zgaritirib bo’ lmaydi.**

var name = “…


This content originally appeared on DEV Community and was authored by asilbek ibragimov

Is string literal mutable or immutable ?
Is string variable mutable or immutable ?

String literal - deb " " ichida constanta sifatida yozilgan stringga aytiladi.

String literal immutable - degani bu qoymatni o'zgaritirib bo' lmaydi.**

var name = "Hello World";
name = "hello world";
var son = 99;
son = 98;
Console.WriteLine(name);
Console.WriteLine(son);

Value typelar - stactkda saqlanadi
Value type deganda, ma'Lumotlar tog'ridan- to'g'ri o'zgaruvchida saqalanadi. Bunda o'zgaruvchining qiymati o'zi bilan birga sagalanadi.
Value typelar stack xotirasida saqlanadi.
Value typega quydagilar kiradi.
Oddiy turlar (int, float, double, char bool va hokazo)
struct, enum.

  int a = 5;
  int b = a;

  b = 10;

  Console.WriteLine(a);
  Console.WriteLine(b);

String metodlari
TrimStart() - function tekstni oldidagi joylarni olib tashlaydi.
TrimEnd() - function tekstni oxiridagi joylarni olib tashlaydi
Trim() - fucntion oldi va oxiridagi joylarni tengdaniga olib tashlaydi.

Bunga misol:

string greeting2 = "Hello"
Console.WriteLine(greeting2);
string trimmedGreeting = greeting2.TrimStart();
Console.WriteLine(trimmedGreeting);
trimmedGreeting = greeting2.TrimEnd();
Console.WriteLine(trimmedGreeting);
trimmedGreeting = (greeting2.Trim);
Console.WriteLine(trimmedGreeting);

Replace()
Function tekst qiymatini o'rniga yangi qiymatga o'zgartirrish imkoniyatini beradi.

 string sayHello= "Hello World";
 Console. WriteLine(sayHello);
 sayHello = sayHello.Replace("Hello", "Greetings");
 Console.WriteLine(sayHello);

ToUpper()
Function xamma harflarni kotta qilib beradi.
ToLower()
Fucntion xamma harflarni kichik qilib beradi.

 Console. WriteLine(sayHello.ToUpper());
 Console. WriteLine(sayHello.ToLower());

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

Format()
Stringni formatlash uchun ishlatiladi.

  var testString = string.Format("Hello {0}", 123123);
  Console.WriteLine("Hello {0:C}", 123123);
  output:Hello 123123

String concatenation - stringlarni bir biriga qo'shish
var greeting = "Hello" + " " + name + " ":
Console.WriteLine(greeting);

Agar space holder ichida o'zgaruvchidan keyin, 10 soni yoziladigan bo lsa bizga consoledan 10 ta joy ajratib beradi.
Agar -10 yoziladigan bo' lsa chap tarfdan rostlab chop etadi.

 var butunSon = 2;
 Console.WriteLine($"Kiritilgan butunSon: {butunSon, 10:D4}" ):
 Console. WriteLine($"Kiritilgan butunSon: butunSon, -10: 04}");

Escape character && verbatim string
Escape character maxsus belgilarni chop etishda backslashda foydalanishimiz kerak - |

Misol uchun:

    var specialString = "U judayam \"zor\" bola";
    Console.WriteLine(specialString):
    Console.WriteLine("olma\n anor\n nok");
    Console.WriteLine("olma \t anor \t nok");
    Console.WriteLine("olma \b anor");
    Console.WriteLine("olma\\anor\\nok");
    Console.WriteLine("C:\\|Windows||System32\\calc.exe");
    Console.WriteLine(@"C:\Windows\System32\calc.exe");
    Console.WriteLine("C: \n Windows \n System32 \n calc.exe");
    Console.WriteLine(@"C: \n Windows \n Systen32 \n calc.exe");


This content originally appeared on DEV Community and was authored by asilbek ibragimov


Print Share Comment Cite Upload Translate Updates
APA

asilbek ibragimov | Sciencx (2024-08-21T14:23:59+00:00) String. Retrieved from https://www.scien.cx/2024/08/21/string/

MLA
" » String." asilbek ibragimov | Sciencx - Wednesday August 21, 2024, https://www.scien.cx/2024/08/21/string/
HARVARD
asilbek ibragimov | Sciencx Wednesday August 21, 2024 » String., viewed ,<https://www.scien.cx/2024/08/21/string/>
VANCOUVER
asilbek ibragimov | Sciencx - » String. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/08/21/string/
CHICAGO
" » String." asilbek ibragimov | Sciencx - Accessed . https://www.scien.cx/2024/08/21/string/
IEEE
" » String." asilbek ibragimov | Sciencx [Online]. Available: https://www.scien.cx/2024/08/21/string/. [Accessed: ]
rf:citation
» String | asilbek ibragimov | Sciencx | https://www.scien.cx/2024/08/21/string/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.