DEV Community

Sunnat Qayumov
Sunnat Qayumov

Posted on

String Operations(Length, escape character, verbatim string)

Length
Stringni uzuznligini qaytaradi

Console.WriteLine( "Hello World".Length ) 
// 11
Enter fullscreen mode Exit fullscreen mode

Ishlatilishi:

var carModel="BYD Song L"
for( int i = 0; i < carModel.Length; i++ )
Console.WriteLine(carModel[i]);
Stringni barcha elementlarini alohida indekslari orqali qaytaradi.
Enter fullscreen mode Exit fullscreen mode

Escape character ( \ )

String ichida yozib bo'lmaydigan belgilarni yozish uchun Escape Character ishlatiladi.

var specialString = " Hello "new" world ";
Console.WriteLine(specialString);
Enter fullscreen mode Exit fullscreen mode

Yuqoridagi holatda qo'shtirnoqni o'qimaydi va error beradi.
Bu xatoni to'girlash uchun belgilar oldidan \ (backslash) ishlatiladi.

var specialString = " Hello \"new\" world ";
Console.WriteLine(specialString);
Enter fullscreen mode Exit fullscreen mode

\n
Yangi qatorga o'tish uchun ishlatiladi

Console.WriteLine( "book \n "pen" );
output:
book
pen
Enter fullscreen mode Exit fullscreen mode

\t
Tab ya'ni 4 ta probel tashlab chop etadi.

Console.WriteLine( "book \t "pen" \t "pencil" );
output:book    pen    pencil
Enter fullscreen mode Exit fullscreen mode

*\*
Backslashni o'zini chop etish uchun 2 ta backslash yozish kifoya.

Console.WriteLine( "\\book\\" );
output:\book\
Enter fullscreen mode Exit fullscreen mode

\b
Backspace ya'ni eng oxirgi yozilgan belgini o'chirib yuboradi.

Console.WriteLine( "book" \b "pen" );
output:boopen
Enter fullscreen mode Exit fullscreen mode

Verbatim string
Biror so'zni o'zgarishsiz ko'chirib aytish yoki yozish uchun ishlatiladi.

Console.WriteLine( "C :\\Users\\User1\\Algo.exe");
output:C :\Users\User1\Algo.exe
Yuqoridagi manzilni quyidagicha ya'ni bitta (@) belgi chop etish qulayroq
Console.WriteLine( @"C :\Users\User1\Algo.exe");
output:C :\Users\User1\Algo.exe
Enter fullscreen mode Exit fullscreen mode

Top comments (0)