Javatpoint Logo
Javatpoint Logo

Go Strings

The Go string is a sequence of variable-width characters.

Go strings and text files occupy less memory or disk space. Since, UTF-8 is the standard, Go doesn't need to encode and decode strings.

Go Strings are value types and immutable. It means if you create a string, you cannot modify the contents of the string. The initial value of a string is empty "" by default.

Go String Example

Output:

Hello World
string

Go String len() Example

Output:

17

Go Print ASCII Example

Output:

Ascii value of A is  65

Go String ToUpper() Example

Output:

INDIA

Go String ToLower() Example

Output:

india

Go String HasPrefix() Example

Output:

true

Go String HasSuffix() Example

Output:

true

Go String Join() Example

Output:

a*b*c*d

Go String Repeat() Example

Output:

New New New New 

Go String Contains() Example

Output:

true

Go String Index() Example

Output:

5

Go String Count() Example

Output:

2

Go String Replace() Example

Output:

Hi...thZrZ  

Go String Split() Example

Output:

4
Index :  0 value :  I
Index :  1 value :  love
Index :  2 value :  my
Index :  3 value :  country

Go String Split() Example 2

Output:

["x" "y" "z"]
[" John " " Jack " " Johnny " " Jinn"]
[" " "a" "b" "c" " "]
[""]

Go String Compare() Example

Output:

-1
0
1

Go String Trim() Example

Output:

I love my country

Go String ContainsAny() Example

Output:

false
true
false
false
Next TopicGo Regex




Help Others, Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA