- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Most writing systems' characters are defined by the universal character set known as Unicode, which also assigns each character a unique number (code point). A unit of data called an abstract character (or character) is used to organize, manage, or represent textual data.
Most of the modern languages' letters, punctuation marks, diacritical markings, mathematical symbols, technical symbols, arrows, emoji, and other symbols are all included in Unicode.
These are different types of Unicode characters are printed in the console.
Using Escape Sequences
Users can follow the below syntax to print escape sequences.
Here\u is a prefix followed by a hexadecimal number <hex> with a fixed length of 4 digits. For example,'\u0051' (symbol 'Q') or '\u222B' (integral symbol '∫'.
The below example demonstrates how to print the Unicode characters – escape sequences in console. The variable s stores a certain Unicode value for space and the letter ‘U’. Then it prints that to the console. Similarly, in the next lines we see the Unicode for happy face emoji and funny cat face emoji.
Here, the reader can observe how space, letters and emoji are printed using the Unicode characters.
In this approach, we will use the strings to check for Unicode characters. The evaluation of code units for a match in a string comparison will be the desired if the code units from the two strings are the same.
Consider comparing two displayed strings that have the same appearance but have distinct code unit sequences. Because strings that superficially appear to be equal are not equal in comparison, you can get an unexpected result.
const a = '\u0068ell\u006F';
Users can learn to perform the string comparison using Unicode characters. We insert "hello" and Unicode characters for 'H' and 'o'. The check is performed, and both strings are the same. Then we check for some other characters. When displayed, s1 and s2 have the same appearance, although they contain distinct code units. It occurs because the ç graphene can be built in one of two ways, one with U+00E7 Latin small letter c with cedilla and another with U+0063 Latin small letter c and U+0327 combining cedilla.
In the above output, users can observe that first a check between both strings is being performed. Then we see s1 and s2 are almost same but are different inserted for the cedilla so they are interpreted as different strings.
Using Unicode Characters in Variable & Function Names
In this tutorial we will see how to put Unicode characters in variable names.
In this example, we see two approaches, one to use Unicode characters as variable names and another to use Unicode characters as Function names. The variable name will be recognized as ‘foo’ and the function name is recognized as ‘fo’ which helps to print Unicode characters in the console.
In this output, we see that the variable’s value is being printed and the function is being recognized as we use Unicode character to declare the variable and function names.
- Related Articles
- How to Remove Unicode from Jenkins Console Output logs using Postman?
- How to print a line on the console using C#?
- How can I clear console using C++?
- How to print Unicode character in C++?
- How to create a plot title with unicode characters using ggplot2 in R?
- How do i Make JS Console Output As Text In HTML?
- How to use Unicode and Special Characters in Tkinter?
- How to print duplicate characters in a String using C#?
- How I can use a database-name with special characters like " customer_tracker-990" in MongoDB console
- How do I print a double value with full precision using cout in C++?