- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
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
Golang Program to demonstrate the escape sequence characters
In the go programming language, there are several types of special escape sequence characters. Usage of each one of them implements a different type of functionality. We shall discuss each one of them one by one in the upcoming examples.
Example 1
In this example, we will write a go language program to demonstrate the backlash (//) character. It is used to display a slash in the output of the program.
package main import "fmt" func main() { fmt.Println("Program to display a backslash using in the program") }
Output
Program to display a backslash using in the program\
Example 2
In this example, we will write a go language program to demonstrate the ascii bell character. It is displayed by \a escape character literal.
package main import "fmt" func main() { fmt.Println("Go landuage program to display an ASCII bell (BEL): \a") }
Output
Go landuage program to display an ASCII bell (BEL):
Example 3
In this example, we will write a go language program to demonstrate the line feed. It is displayed by \n escape character literal and is used to start a new line. The string/numbers that are written after this character come in a new line.
package main import "fmt" func main() { fmt.Println("Go landuage program to show a line feed. \nThis string will be displayed in a new line.") }
Output
Go landuage program to show a line feed. This string will be displayed in a new line.
Example 4
In this example, we will write a go language program to demonstrate the carriage return. It is displayed by \r escape character literal and is used to start a new line. The difference between line feed and carriage return is that this return character gives a small space in the starting character of the new line.
package main import "fmt" func main() { fmt.Println("Go languaage program to display carriage return (CR): \r This is second statement and appears in the new line.") }
Output
Go languaage program to display carriage return (CR): This is second statement and appears in the new line.
Example 5
In this example, we will write a go language program to demonstrate the Horizontal tab. It is displayed by \t escape character literal and is used to give a space after the data where it is displayed.
package main import "fmt" func main() { fmt.Println("Go language program to display ASCII horizontal tab (TAB): \n This is second statement and appears after a space") }
Output
Go language program to display ASCII horizontal tab (TAB): This is second statement and appears after a space
Example 6
In this example, we will write a go language program to demonstrate the double quotations. It is displayed by \” escape character literal and is used to encapsulate the data in the double quotations that is entered within it.
package main import "fmt" func main() { fmt.Println("Golang program to display Double quote string literal (∖"this will come in quotations ∖"): ") }
Output
Golang program to display Double quote string literal ("this will come in quotations"):
Example 7
In this example, we will write a go language program to demonstrate Unicode escape sequence character. It is displayed by \u and is used to include hexadecimal digits within the program.
package main import "fmt" func main() { fmt.Printf("Go language program to display a Unicode code point (Heart): %c", '\u2665') }
Output
Go language program to display a Unicode code point (Heart): ♥
Example 8
In this example, we will write a go language program to demonstrate hexadecimal escape sequence character. It is displayed by \x and is used to represent a character by its hexadecimal code.
package main import "fmt" func main() { fmt.Printf("Go language program to show Hexadecimal escape sequence character (Star): %c", '\x2a') }
Output
Go language program to show Hexadecimal escape sequence character (Star): *
Conclusion
We have successfully compiled and executed a go language program to demonstrate the escape sequence characters along with examples. In this article we have shown the shown different escape sequence literal characters along with their usage.
- Related Articles
- Golang Program to demonstrate the string concatenation
- Golang program to demonstrate the time arithmetic
- Golang program to demonstrate the string interpolation
- Golang program to demonstrate the argument passing to block
- Golang program to demonstrate a simple module
- Golang program to demonstrate BEGIN and END blocks
- Escape Characters in Python
- Escape characters in JavaScript
- Golang program to demonstrate passing of pointers to a function
- Ways to print escape characters in C#
- Ways to print escape characters in python
- Golang Program to demonstrate the example to write double quotes in a string
- Golang program to swapping pair of characters
- Golang program to find the duplicate characters in the string
- Golang Program to get characters from a string using the index
