<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>string on Golang</title><link>https://golang.k5kc.com/tags/string/</link><description>Recent content in string on Golang</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Sun, 16 Aug 2020 00:10:00 +0530</lastBuildDate><atom:link href="https://golang.k5kc.com/tags/string/index.xml" rel="self" type="application/rss+xml"/><item><title>Go - String</title><link>https://golang.k5kc.com/2020/08/16/3.string/</link><pubDate>Sun, 16 Aug 2020 00:10:00 +0530</pubDate><guid>https://golang.k5kc.com/2020/08/16/3.string/</guid><description>In Go, string is an immutable array of bytes. So if created, we can&amp;rsquo;t change its value. E.g.:
package main func main() { s := &amp;#34;Hello&amp;#34; s[0] = &amp;#39;h&amp;#39; } The compiler will complain:
cannot assign to s[0]
To modify the content of a string, you could convert it to a byte array. But in fact, you do not operate on the original string, just a copy:
package main import &amp;#34;fmt&amp;#34; func main() { s := &amp;#34;Hello&amp;#34; b := []byte(s) b[0] = &amp;#39;h&amp;#39; fmt.</description></item><item><title>Go - Type conversion</title><link>https://golang.k5kc.com/2020/08/16/4.type-conversion/</link><pubDate>Sun, 16 Aug 2020 00:10:00 +0530</pubDate><guid>https://golang.k5kc.com/2020/08/16/4.type-conversion/</guid><description>The expression T(v) converts the value v to the type T. Some numeric conversions:
var i int = 42 var f float64 = float64(i) var u uint = uint(f) Or, put more simply:
i := 42 f := float64(i) u := uint(f) Go assignment between items of different type requires an explicit conversion which means that you manually need to convert types if you are passing a variable to a function expecting another type.</description></item></channel></rss>