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 Han"
for ( int i = 0; i < carModel.Length; i++ )
Console.WriteLine(carModel[i]);
Enter fullscreen mode
Exit fullscreen mode

Stringni barcha elementlarini alohida indekslari orqali qaytaradi.

Escape character ( \ )

String ichida yozib bo’lmaydigan belgilarni yozish uchn 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

\r
Kursorni qator boshiga qaytarib qo’yadi

Console.WriteLine( "book" \r "pen" );
output:penb
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
Enter fullscreen mode
Exit fullscreen mode

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

Discover more from Coursity

Subscribe to get the latest posts sent to your email.

Leave a Comment

Your email address will not be published. Required fields are marked *

Discover more from Coursity

Subscribe now to keep reading and get access to the full archive.

Continue reading

Scroll to Top
Learn tips on preventing hacking of smart home devices with our expert cybersecurity advice. Unlock the power of digital literacy.