Go Programming Language String Data Type

Go Programming Language String Data Type

In Go programming, string data type and also predefined string manipulation operations are available.

Hoow to declare string variablee in Go programming ?

var str string

How to assign string variable in Go programming ?

var str string
str = "codingpointer.com!"

Another way

str := "codingpointer.com!"

any one of the way can be used to define string variables.

How to get user string input in Go programming ?

fmt.Sprintf("%s", &str)

Sprintf function in fmt package is used to get the user input and need to use %s with Sprintf funtion to get string user input in Go programming.

Using string data type and print data

Simple Go program declares string data type variable, assigning value and prints the string variable data.

package main                                                               	 
import "fmt"                                                               	 
func main() {                                                              	 
	var str string                                                         	 
	str = "codingpointer.com!"                                             	 
$ go build print-string.go
$ ./print-string

String Manipulations

In Go programming, built in functions and operators are available to manipulate strings. strings and strconv packages are used for string manipulations.

strconv.ParseInt, strconv.ParseFloat, strings.Split, strings.ToUpper, strings.ToLower are some of the functions used for string manipulations in Go.