DEV Community

Sunnat Qayumov
Sunnat Qayumov

Posted on

3 3 3 3 3

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

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 (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay