Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Strings | Section
Practice
Projects
Quizzes & Challenges
Quiz
Challenges
/
Getting Started with Go

bookStrings

Glissez pour afficher le menu

In Go, strings are sequences of Unicode characters, which essentially means they represent textual data. String data is always enclosed in double quotation marks (") or backticks. The string data type is represented by the string keyword.

index.go

index.go

copy
1
var myString string = "Hello World"

Note

A string is a data type in Go, while a string literal refers to the actual representation of a string value within the source code, for example, Hello World.

We can write a string literal in multiple lines by enclosing it in backticks (``). You can see the difference in the following program:

index.go

index.go

copy
1234567891011121314
package main import "fmt" func main() { var myString string // Using double quotes ("") myString = "Hello World" fmt.Println(myString) // Using backticks (``) myString = `Hello World` fmt.Println(myString) }

Strings can be joined together using the plus (+) operator:

index.go

index.go

copy
1234567891011
package main import "fmt" func main() { var stringOne string = "Hello" var stringTwo string = "World" var stringThree string = stringOne + " " + stringTwo fmt.Println(stringThree) }

The process of joining two strings using the (+) operator is called string concatenation.

question mark

Which of the following is the correct way to declare a string variable in Go?

Select all correct answers

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 1. Chapitre 15

Demandez à l'IA

expand

Demandez à l'IA

ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

Section 1. Chapitre 15
some-alt