# String

Tipe data string digunakan untuk menyimpan value berupa karakter. Default value dari tipe data string adalah karakter kosong atau "".

## Contoh code

```go
package main

import "fmt"

var str string

func main() {
    if str == "" {
        fmt.Println("it is an empty string")
    }
    str = "test"
    fmt.Println(str)
}
```

```
it is an empty string
test
```

## String dan Byte

Di golang string disimpan dalam bentul slice dengan tipe data byte. Untuk menampilkan setiap nilai byte pada 1 karakter di dalam string dapat menggunakan *code* berikut.

```go
package main

import "fmt"

var sample string = "please"

func main() {
    for i := 0; i < len(sample); i++ {
        fmt.Printf("%x ", sample[i])
    }
}
```

```
70 6c 65 61 73 65 
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://rafli-ramadhan.gitbook.io/golang-example-code-by-topic/tipe-data-primitif/string.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
