Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does this C# string format mean?

Tags:

string

c#

From my previous question, Converting chinese character to Unicode, I had a good answer but with some code I didn't understand:

Console.WriteLine("U+{0:x4}", (int)myChar);

Could anyone explain this?

like image 873
Mass Avatar asked Mar 12 '26 13:03

Mass


1 Answers

Console.WriteLine("U+{0:x4}", (int)myChar);

is the equivalent to the call:

Console.WriteLine("U+{0}", ((int)myChar).ToString("x4"));

In a format string, the : indicates that the item should be displayed using the provided format. The x4 part indicates that the integer should be printed in its hexadecimal form using 4 characters. Refer to standard numeric format strings for more information.

like image 90
Jeff Mercado Avatar answered Mar 14 '26 03:03

Jeff Mercado



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!