{"id":775,"date":"2026-10-05T15:00:00","date_gmt":"2026-10-05T09:30:00","guid":{"rendered":"https:\/\/smitabharat.com\/blog\/go-string-programs\/"},"modified":"2026-11-29T01:29:39","modified_gmt":"2026-11-28T19:59:39","slug":"go-string-programs","status":"publish","type":"post","link":"https:\/\/smitabharat.com\/blog\/go-string-programs\/","title":{"rendered":"Go String Programs with Output: Reverse, Palindrome, Count"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Go string programs are among the most asked coding questions, because almost every app works with text such as names, messages and search words. In this post, you will write twelve string programs with their exact output, including reverse a string, palindrome check, vowel count, word count and character frequency. Then you will practice the string questions that test how Go stores text in memory.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This post starts Level 3 of our Go programs series. It uses the loops from our <a href=\"https:\/\/smitabharat.com\/blog\/go-loop-programs\/\">Go loop programs<\/a> and the rune idea from our <a href=\"https:\/\/smitabharat.com\/blog\/go-hello-world-print-programs\/\">Go print programs<\/a>. For the theory of strings, read the <a href=\"https:\/\/smitabharat.com\/blog\/go-strings-examples\/\">Go strings guide with examples<\/a>. We tested every program on Go 1.27.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What are Go String Programs?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Go string programs read, check or change text. A Go string is a read-only list of bytes that usually holds UTF-8 text. A rune is one Unicode character, such as &#8220;a&#8221;, &#8220;\u00e9&#8221; or &#8220;\u0928&#8221;.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Think of a string as a train. Each byte is a seat, but some passengers, like Hindi letters, need three seats. If you count seats, you get bytes. If you count passengers, you get runes. Most string bugs come from mixing these two up.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Go String Programs Matter<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Text is everywhere in real software. For example, you clean user names, search product titles and count words in reviews. So Go string programs show up in almost every coding round, often as the first question.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Interviews:<\/strong> reverse a string and palindrome checks are classic warm-up questions.<\/li>\n\n\n<li><strong>Unicode skill:<\/strong> they test whether you know bytes from runes.<\/li>\n\n\n<li><strong>Real work:<\/strong> the <code>strings<\/code> package is one of the most used packages in Go.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">How Go String Programs Work<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Most Go string programs follow the same steps. First, you turn the string into runes when characters matter. Next, you loop over the runes and apply your rule. Finally, you turn the result back into a string.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-string-programs-diagram-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-string-programs-diagram-1-1024x640.png\" alt=\"Go string programs diagram showing a string turned into runes, processed and joined back\" class=\"wp-image-772\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-string-programs-diagram-1-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-string-programs-diagram-1-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-string-programs-diagram-1-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-string-programs-diagram-1-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-string-programs-diagram-1-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Convert the string to runes, work on each character, then convert back to a string.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The table below lists the tools that Go string programs use most.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Tool<\/th><th>What it does<\/th><th>Example result<\/th><\/tr><\/thead><tbody><tr><td>len(s)<\/td><td>Counts bytes<\/td><td>len(&#8220;h\u00e9llo&#8221;) is 6<\/td><\/tr><tr><td>[]rune(s)<\/td><td>Splits into characters<\/td><td>5 runes for &#8220;h\u00e9llo&#8221;<\/td><\/tr><tr><td>for i, r := range s<\/td><td>Loops over runes<\/td><td>r is each character<\/td><\/tr><tr><td>strings.ToLower<\/td><td>Makes text lower case<\/td><td>&#8220;GO&#8221; becomes &#8220;go&#8221;<\/td><\/tr><tr><td>strings.Fields<\/td><td>Splits on spaces<\/td><td>3 words for &#8220;Go is fun&#8221;<\/td><\/tr><tr><td>strings.Builder<\/td><td>Builds text fast<\/td><td>Joins many pieces cheaply<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Basic Go String Programs<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These first Go string programs are the ones you will meet most often. We start with two very easy warm-ups, so you get used to how strings behave.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 1: Print Each Letter of a String<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This program prints a word, its length, and then every letter with its position.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    word := \"Gopher\" \/\/ := creates a new variable and sets its value\n\n    fmt.Println(\"Word:\", word)\n    fmt.Println(\"Length:\", len(word)) \/\/ len counts the bytes in the string\n\n    \/\/ range gives the position and the letter (a rune) on each turn.\n    for index, letter := range word {\n        fmt.Println(index, string(letter)) \/\/ string() turns the rune back into text\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Word: Gopher\nLength: 6\n0 G\n1 o\n2 p\n3 h\n4 e\n5 r<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>len(word)<\/code> gives 6, because each English letter takes one byte. The <code>for<\/code> loop with <code>range<\/code> visits the letters one by one. We wrap each letter in <code>string()<\/code>, or Go would print its number code instead.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 2: Join Two Strings<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">You can glue strings together with the <code>+<\/code> sign. This is called concatenation.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    firstName := \"Ravi\"\n    lastName := \"Kumar\"\n\n    \/\/ Step 1: join the two names with a space in the middle.\n    fullName := firstName + \" \" + lastName\n\n    \/\/ Step 2: build a greeting from the full name.\n    greeting := \"Hello, \" + fullName + \"!\"\n\n    fmt.Println(greeting)\n    fmt.Println(\"Letters and space:\", len(fullName))\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Hello, Ravi Kumar!\nLetters and space: 10<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>+<\/code> sign makes a brand new string from the pieces. We add <code>\" \"<\/code> in the middle, or the names would stick together. The full name has 9 letters plus 1 space, so its length is 10.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 3: Reverse a String<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To reverse correctly, we work with runes, not bytes. This keeps letters like &#8220;\u00e9&#8221; in one piece.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\n\/\/ reverse returns the text with its characters in the opposite order.\nfunc reverse(text string) string {\n    letters := []rune(text) \/\/ a slice (list) of characters we can change\n    last := len(letters) - 1\n\n    \/\/ Walk from the front to the middle and swap with the matching back letter.\n    for i := 0; i &lt; len(letters)\/2; i++ {\n        j := last - i\n        letters[i], letters[j] = letters[j], letters[i] \/\/ swap the two letters\n    }\n    return string(letters) \/\/ join the runes back into a string\n}\n\nfunc main() {\n    fmt.Println(reverse(\"golang\"))\n    fmt.Println(reverse(\"caf\u00e9\"))\n    fmt.Println(reverse(\"\u0928\u092e\u0938\u094d\u0924\u0947\"))\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>gnalog\n\u00e9fac\n\u0947\u0924\u094d\u0938\u092e\u0928<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The loop swaps the first letter with the last, then the second with the second last, and so on. It stops at the middle, so each pair swaps only once. The Hindi word reverses rune by rune, so its vowel signs can look odd. Real text sometimes needs grapheme handling, which the standard library does not provide.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 4: Palindrome String Check<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A palindrome reads the same both ways. We ignore case and anything that is not a letter or digit.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"strings\"\n    \"unicode\"\n)\n\n\/\/ isPalindrome reports whether the letters and digits read the same both ways.\nfunc isPalindrome(text string) bool {\n    \/\/ Step 1: keep only small letters and digits.\n    var clean []rune \/\/ an empty slice of runes\n    for _, letter := range strings.ToLower(text) {\n        if unicode.IsLetter(letter) || unicode.IsDigit(letter) {\n            clean = append(clean, letter) \/\/ append adds the letter at the end\n        }\n    }\n\n    \/\/ Step 2: compare the front and back, moving toward the middle.\n    last := len(clean) - 1\n    for i := 0; i &lt; len(clean)\/2; i++ {\n        if clean[i] != clean[last-i] {\n            return false\n        }\n    }\n    return true\n}\n\nfunc main() {\n    sentences := []string{\"Madam\", \"A man, a plan, a canal: Panama\", \"Golang\"}\n\n    for _, sentence := range sentences {\n        fmt.Printf(\"%q -&gt; %t\\n\", sentence, isPalindrome(sentence)) \/\/ %q adds quotes, %t prints true or false\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\"Madam\" -&gt; true\n\"A man, a plan, a canal: Panama\" -&gt; true\n\"Golang\" -&gt; false<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">We first build a clean list of runes, without spaces or commas. Then we compare letters from both ends. If any pair differs, the answer is false. This is the exact version asked in LeetCode style rounds.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 5: Count Vowels and Consonants<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"strings\"\n    \"unicode\"\n)\n\nfunc main() {\n    text := \"Go is Simple and Fast\"\n    vowels := 0\n    consonants := 0\n\n    for _, letter := range strings.ToLower(text) {\n        if !unicode.IsLetter(letter) { \/\/ ! means \"not\"\n            continue \/\/ skip spaces and go to the next character\n        }\n        \/\/ ContainsRune checks if the letter is one of \"aeiou\".\n        if strings.ContainsRune(\"aeiou\", letter) {\n            vowels++\n        } else {\n            consonants++\n        }\n    }\n    fmt.Println(\"Vowels:\", vowels)\n    fmt.Println(\"Consonants:\", consonants)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Vowels: 6\nConsonants: 11<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">We make the text lower case first, so &#8220;G&#8221; and &#8220;g&#8221; are treated the same. Spaces are skipped with <code>continue<\/code>, so only letters are counted. Each letter then adds one to either <code>vowels<\/code> or <code>consonants<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 6: Count Words<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>strings.Fields<\/code> splits on any run of spaces, tabs or new lines. So extra spaces do not create empty words.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"strings\"\n)\n\nfunc main() {\n    text := \"  Go   makes  backend work   simple  \"\n\n    words := strings.Fields(text) \/\/ a slice with one item per word\n\n    fmt.Println(\"Words:\", len(words))\n    fmt.Printf(\"%q\\n\", words) \/\/ %q shows each word in quotes\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Words: 5\n[\"Go\" \"makes\" \"backend\" \"work\" \"simple\"]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>strings.Fields<\/code> throws away all the extra spaces and keeps the words. So <code>len(words)<\/code> gives the word count. If you used <code>strings.Split(text, \" \")<\/code> here, you would get many empty strings. That is a common bug.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 7: Character Frequency<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">We count each character in a map, then print the keys in sorted order so the output stays the same every run.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"maps\"\n    \"slices\"\n)\n\nfunc main() {\n    \/\/ A map links each letter (key) to how many times we saw it (value).\n    counts := map[rune]int{}\n\n    for _, letter := range \"programming\" {\n        counts[letter]++ \/\/ a missing key starts at 0, so this works for new letters\n    }\n\n    \/\/ maps.Keys gives all the letters, and slices.Sorted puts them in order.\n    sortedLetters := slices.Sorted(maps.Keys(counts))\n\n    for _, letter := range sortedLetters {\n        fmt.Printf(\"%c:%d \", letter, counts[letter]) \/\/ %c prints a rune as a letter\n    }\n    fmt.Println()\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>a:1 g:2 i:1 m:2 n:1 o:1 p:1 r:2<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>counts[letter]++<\/code> works even for a new key, because a missing key starts at 0. Maps have no fixed order, so we sort the letters before printing. We cover maps fully in our map programs post in this level.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Go String Programs with the strings Package<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>strings<\/code> package does most common jobs for you. These programs show the functions you will use daily.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 8: Change Case and Trim<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"strings\"\n)\n\nfunc main() {\n    message := \"   Hello, Gopher!   \"\n\n    \/\/ TrimSpace removes spaces from both ends. The [ ] show where the text stops.\n    fmt.Printf(\"[%s]\\n\", strings.TrimSpace(message))\n\n    \/\/ ToUpper changes letters to capitals but keeps the spaces.\n    fmt.Println(strings.ToUpper(message))\n\n    \/\/ First trim, then make everything lower case.\n    fmt.Println(strings.ToLower(strings.TrimSpace(message)))\n\n    \/\/ Title is old (deprecated), but it still works for simple English.\n    fmt.Println(strings.Title(\"not used anymore\") == \"Not Used Anymore\")\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>[Hello, Gopher!]\n   HELLO, GOPHER!\nhello, gopher!\ntrue<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Each line calls one <code>strings<\/code> function on the same message. The original <code>message<\/code> never changes, because each function returns a new string. <code>strings.Title<\/code> still works but is deprecated, because it fails for many languages. Use the <code>golang.org\/x\/text\/cases<\/code> package in real code.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 9: Search Inside a String<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"strings\"\n)\n\nfunc main() {\n    sentence := \"learn go, write go, love go\"\n\n    fmt.Println(strings.Contains(sentence, \"write\"))  \/\/ is \"write\" inside?\n    fmt.Println(strings.Index(sentence, \"go\"))        \/\/ position of the first \"go\"\n    fmt.Println(strings.LastIndex(sentence, \"go\"))    \/\/ position of the last \"go\"\n    fmt.Println(strings.Count(sentence, \"go\"))        \/\/ how many times \"go\" appears\n    fmt.Println(strings.HasPrefix(sentence, \"learn\"), strings.HasSuffix(sentence, \"go\"))\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>true\n6\n25\n3\ntrue true<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>Index<\/code> returns the byte position of the first match, or -1 if there is none. Positions start at 0, so the first &#8220;go&#8221; is at 6. <code>Count<\/code> returns how many times the text appears without overlap.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 10: Replace and Split<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"strings\"\n)\n\nfunc main() {\n    csv := \"pen,book,,bag\"\n\n    \/\/ Split cuts the text at every comma.\n    parts := strings.Split(csv, \",\")\n    fmt.Printf(\"%d parts: %q\\n\", len(parts), parts)\n\n    fmt.Println(strings.ReplaceAll(\"a-b-c\", \"-\", \"\/\")) \/\/ change every \"-\"\n    fmt.Println(strings.Replace(\"a-b-c\", \"-\", \"\/\", 1)) \/\/ change only the first \"-\"\n\n    \/\/ Join puts the words back together with a space between them.\n    fmt.Println(strings.Join([]string{\"go\", \"is\", \"fun\"}, \" \"))\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>4 parts: [\"pen\" \"book\" \"\" \"bag\"]\na\/b\/c\na\/b-c\ngo is fun<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>Split<\/code> keeps the empty part between two commas. <code>Replace<\/code> with 1 changes only the first match, while <code>ReplaceAll<\/code> changes all of them. <code>Join<\/code> does the opposite of <code>Split<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 11: Build a String Fast with strings.Builder<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Joining strings with <code>+<\/code> in a loop creates a new string each time. <code>strings.Builder<\/code> grows one buffer instead.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"strings\"\n)\n\nfunc main() {\n    var builder strings.Builder \/\/ an empty builder, ready to use\n\n    for i := 1; i &lt;= 5; i++ {\n        \/\/ Fprintf writes into the builder. &amp; passes the builder itself, not a copy.\n        fmt.Fprintf(&amp;builder, \"%d,\", i*i)\n    }\n\n    \/\/ String() gives the text so far. TrimSuffix cuts the last comma.\n    result := strings.TrimSuffix(builder.String(), \",\")\n\n    fmt.Println(result)\n    fmt.Println(\"Length:\", builder.Len())\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>1,4,9,16,25\nLength: 12<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The loop writes each square and a comma into the builder. After the loop, we take the text out and remove the extra comma. <code>builder.Len()<\/code> is 12 because the builder still holds the last comma. We removed it only in <code>result<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 12: Count Uppercase, Lowercase, Digits and Spaces<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"unicode\"\n)\n\nfunc main() {\n    text := \"Go 1.27 Rocks!\"\n    var upper, lower, digits, spaces, others int \/\/ all start at 0\n\n    for _, letter := range text {\n        switch {\n        case unicode.IsUpper(letter):\n            upper++\n        case unicode.IsLower(letter):\n            lower++\n        case unicode.IsDigit(letter):\n            digits++\n        case unicode.IsSpace(letter):\n            spaces++\n        default:\n            others++\n        }\n    }\n    fmt.Println(upper, lower, digits, spaces, others)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>2 5 3 2 2<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Each character goes through the switch and adds one to exactly one counter. The two &#8220;other&#8221; characters are the dot and the exclamation mark. A switch with no value keeps the checks tidy, as in our <a href=\"https:\/\/smitabharat.com\/blog\/go-switch-calculator-programs\/\">Go switch programs<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Bytes vs Runes in Go String Programs<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Knowing when to use bytes and when to use runes is the key skill in Go string programs. The diagram and table below compare them.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-string-programs-diagram-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-string-programs-diagram-2-1024x640.png\" alt=\"Go string programs comparison of bytes and runes\" class=\"wp-image-773\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-string-programs-diagram-2-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-string-programs-diagram-2-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-string-programs-diagram-2-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-string-programs-diagram-2-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-string-programs-diagram-2-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Bytes are fast and fine for plain ASCII, while runes keep every Unicode character whole.<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>Bytes (s[i])<\/th><th>Runes ([]rune or range)<\/th><\/tr><\/thead><tbody><tr><td>Unit<\/td><td>One byte<\/td><td>One Unicode character<\/td><\/tr><tr><td>Type<\/td><td>byte (uint8)<\/td><td>rune (int32)<\/td><\/tr><tr><td>len(&#8220;h\u00e9llo&#8221;)<\/td><td>6<\/td><td>5 runes<\/td><\/tr><tr><td>Safe for Hindi or emoji<\/td><td>No<\/td><td>Yes<\/td><\/tr><tr><td>Speed<\/td><td>Fastest<\/td><td>A little slower<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">In short, use bytes for plain ASCII data like IDs. Use runes whenever users can type the text.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes in Go String Programs<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Reversing bytes:<\/strong> reversing <code>[]byte(s)<\/code> breaks letters like &#8220;\u00e9&#8221;. Reverse <code>[]rune(s)<\/code> instead.<\/li>\n\n\n<li><strong>Using len for character count:<\/strong> <code>len<\/code> counts bytes, so use <code>utf8.RuneCountInString(s)<\/code>.<\/li>\n\n\n<li><strong>Changing a string in place:<\/strong> strings are read-only, so <code>s[0] = 'G'<\/code> does not compile.<\/li>\n\n\n<li><strong>Splitting on one space:<\/strong> <code>strings.Split(s, \" \")<\/code> makes empty words. Use <code>strings.Fields<\/code>.<\/li>\n\n\n<li><strong>Joining with + in a big loop:<\/strong> it is slow, so use <code>strings.Builder<\/code>.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for Go String Programs<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Use range or []rune<\/strong> for user text, so every character stays whole.<\/li>\n\n\n<li><strong>Use the strings package<\/strong> before writing your own loops.<\/li>\n\n\n<li><strong>Build long output with strings.Builder<\/strong>, which avoids extra copies.<\/li>\n\n\n<li><strong>Normalise case first<\/strong> with <code>strings.ToLower<\/code> when comparing words.<\/li>\n\n\n<li><strong>Sort map keys before printing<\/strong>, so results stay the same on every run.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Go String Programs Interview Questions and Answers<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Interviewers use short Go string programs to test how well you understand text in Go. Each program is complete, with real output from Go 1.27.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Bytes and Runes in Go String Programs<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q1. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"unicode\/utf8\"\n)\n\nfunc main() {\n    text := \"Go\u20ac\"\n    \/\/ bytes, characters counted by utf8, characters counted with []rune\n    fmt.Println(len(text), utf8.RuneCountInString(text), len([]rune(text)))\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>5 3 3<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The euro sign takes 3 bytes, so <code>len<\/code> gives 5. Both <code>RuneCountInString<\/code> and <code>len([]rune(text))<\/code> give the real character count, 3.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q2. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    word := \"hello\"\n    fmt.Println(word[1], string(word[1])) \/\/ word[1] is the byte at position 1\n    fmt.Printf(\"%T %T\\n\", word[1], 'e')   \/\/ %T prints the type\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>101 e\nuint8 int32<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Indexing a string gives a byte, which prints as a number. A rune literal like &#8216;e&#8217; is an <code>int32<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q3. Why does this program not compile?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    word := \"hello\"\n    word[0] = 'H' \/\/ not allowed: strings cannot be changed\n    fmt.Println(word)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>cannot assign to word[0] (neither addressable nor a map index expression)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Strings are immutable in Go. To change one, convert to <code>[]byte<\/code> or <code>[]rune<\/code>, change it, then convert back.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q4. How do you change the first letter of a string?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    word := \"hello\"\n    letters := []byte(word) \/\/ a changeable copy of the bytes\n    letters[0] = 'H'\n    fmt.Println(string(letters), word)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Hello hello<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The conversion makes a copy, so the original string stays &#8220;hello&#8221;. We change the copy and turn it back into a string to print it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q5. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    for index, letter := range \"a\u00e9\" {\n        fmt.Println(index, string(letter))\n    }\n\n    word := \"a\u00e9\"\n    fmt.Println(word[1:])          \/\/ [1:] means from byte 1 to the end\n    fmt.Printf(\"%q\\n\", word[1:2])  \/\/ only byte 1\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>0 a\n1 \u00e9\n\u00e9\n\"\\xc3\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>word[1:]<\/code> keeps both bytes of &#8220;\u00e9&#8221;, so it prints fine. But <code>word[1:2]<\/code> cuts the character in half, which leaves one invalid byte.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">strings Package Questions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q6. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"strings\"\n)\n\nfunc main() {\n    fmt.Println(strings.Index(\"chicken\", \"ken\"))  \/\/ where \"ken\" starts\n    fmt.Println(strings.Index(\"chicken\", \"dmr\"))  \/\/ not found\n    fmt.Println(strings.EqualFold(\"Go\", \"GO\"))    \/\/ equal if we ignore case?\n    fmt.Println(strings.Repeat(\"ab\", 3))\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>4\n-1\ntrue\nababab<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">&#8220;ken&#8221; starts at byte 4 of &#8220;chicken&#8221;, and &#8220;dmr&#8221; is not there, so you get -1. <code>EqualFold<\/code> ignores upper and lower case. <code>Repeat<\/code> writes &#8220;ab&#8221; three times.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q7. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"strings\"\n)\n\nfunc main() {\n    fmt.Printf(\"%q\\n\", strings.Split(\"a,b,c\", \",\"))\n    fmt.Printf(\"%q\\n\", strings.Split(\"\", \",\"))\n    fmt.Printf(\"%q\\n\", strings.Fields(\"\"))\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>[\"a\" \"b\" \"c\"]\n[\"\"]\n[]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Splitting an empty string gives one empty item, not zero. <code>Fields<\/code> on an empty string gives an empty slice, which is often what you want.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q8. What is the difference between strings.Trim and strings.TrimSpace?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"strings\"\n)\n\nfunc main() {\n    fmt.Println(strings.Trim(\"xxhixx\", \"x\"))\n    fmt.Println(strings.TrimSpace(\"  hi  \"))\n    fmt.Println(strings.TrimPrefix(\"go-lang\", \"go-\"))\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>hi\nhi\nlang<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>Trim<\/code> removes any of the given characters from both ends. <code>TrimSpace<\/code> removes white space only, and <code>TrimPrefix<\/code> removes one exact prefix.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q9. How do you compare strings in Go?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use <code>==<\/code> for exact equality and <code>&lt;<\/code> or <code>&gt;<\/code> for dictionary order. <code>strings.Compare<\/code> also exists, but <code>==<\/code> is clearer and faster.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    fmt.Println(\"apple\" &lt; \"banana\", \"Zoo\" &lt; \"apple\", \"go\" == \"go\")\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>true true true<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Capital letters come before lower case in byte order, so &#8220;Zoo&#8221; is smaller than &#8220;apple&#8221;.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Output and Performance Questions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q10. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"strconv\"\n)\n\nfunc main() {\n    code := 65\n    fmt.Println(string(rune(code)))    \/\/ the character with code 65\n    fmt.Println(strconv.Itoa(code))    \/\/ Itoa turns the number into text\n    fmt.Println(fmt.Sprint(code) + \"!\") \/\/ Sprint also turns it into text\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>A\n65\n65!<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>string(rune(65))<\/code> gives the character with code 65, which is &#8220;A&#8221;. To get the text &#8220;65&#8221;, use <code>strconv.Itoa<\/code> or <code>fmt.Sprint<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q11. Why is strings.Builder faster than + in a loop?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Each <code>+<\/code> creates a brand new string and copies both sides. <code>strings.Builder<\/code> keeps one growing buffer, so it copies far less data. For a few joins, <code>+<\/code> is fine.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q12. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    raw := `line1\\nline2`    \/\/ back quotes: \\n stays as two characters\n    normal := \"line1\\nline2\" \/\/ double quotes: \\n is one new line\n    fmt.Println(len(raw), len(normal))\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>12 11<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In a raw string, <code>\\n<\/code> is two real characters. In a normal string, it is one new line character.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q13. How do you check if a string contains only digits?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"unicode\"\n)\n\n\/\/ onlyDigits reports whether text has at least one character and all are digits.\nfunc onlyDigits(text string) bool {\n    if text == \"\" {\n        return false\n    }\n    for _, letter := range text {\n        if !unicode.IsDigit(letter) {\n            return false \/\/ one non-digit is enough to stop\n        }\n    }\n    return true\n}\n\nfunc main() {\n    fmt.Println(onlyDigits(\"2026\"), onlyDigits(\"20a6\"), onlyDigits(\"\"))\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>true false false<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The loop stops at the first character that is not a digit. We return false for an empty string on purpose. Decide this edge case early, because interviewers often ask about it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q14. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"strings\"\n)\n\nfunc main() {\n    original := \"Go\"\n    copied := original\n    copied += \" rocks\" \/\/ makes a new string for copied only\n\n    fmt.Println(original, \"|\", copied)\n\n    \/\/ [:1] is the first byte, [1:] is everything after it.\n    fmt.Println(strings.ToUpper(original[:1]) + original[1:])\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Go | Go rocks\nGo<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>copied += \" rocks\"<\/code> creates a new string for <code>copied<\/code>. The <code>original<\/code> string does not change, because strings are values that cannot be changed.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Practice Task<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This task reuses ideas from several Go string programs above. Write a program that finds the longest word in a sentence and prints it with its length. If two words have the same length, keep the first one. Hint: use <code>strings.Fields<\/code> and compare with <code>&gt;<\/code> so ties keep the earlier word.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Official Resources<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/pkg.go.dev\/strings\">strings package documentation<\/a><\/li>\n\n\n<li><a href=\"https:\/\/pkg.go.dev\/unicode\/utf8\">unicode\/utf8 package documentation<\/a><\/li>\n\n\n<li><a href=\"https:\/\/go.dev\/blog\/strings\">Strings, bytes, runes and characters in Go (Go blog)<\/a><\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Quick Recap<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Go string programs should use runes for user text and bytes only for plain ASCII.<\/li>\n\n\n<li><code>len<\/code> counts bytes, while <code>utf8.RuneCountInString<\/code> counts characters.<\/li>\n\n\n<li>Strings cannot be changed in place, so convert to <code>[]rune<\/code> or <code>[]byte<\/code> first.<\/li>\n\n\n<li><code>strings.Fields<\/code>, <code>Contains<\/code>, <code>Index<\/code>, <code>Replace<\/code> and <code>Join<\/code> cover most daily needs.<\/li>\n\n\n<li>Use <code>strings.Builder<\/code> when you build long strings in a loop.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What&#8217;s Next?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Next, we go deeper with harder text problems. Read <a href=\"https:\/\/smitabharat.com\/blog\/go-string-manipulation-programs\/\">Go string manipulation programs<\/a>, with anagrams, duplicate removal and the first non-repeating character. To revise the interview side, see the <a href=\"https:\/\/smitabharat.com\/blog\/go-strings-interview-questions-part-6\/\">Go strings interview questions<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Go string programs are among the most asked coding questions, because almost every app works with text such as names, messages and search words.&hellip;<\/p>\n","protected":false},"author":1,"featured_media":774,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_swapz_level":"","_swapz_series_part":0,"_swapz_hide_toc":false,"_swapz_hide_featured":false,"_swapz_description":"","footnotes":""},"categories":[106],"tags":[96,95,11,104,47],"swapz_series":[],"class_list":["post-775","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-go-programs","tag-beginner","tag-go-interview-questions","tag-go-lang","tag-go-programs","tag-go-strings"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Go String Programs: Reverse, Palindrome, Count<\/title>\n<meta name=\"description\" content=\"Go string programs with output: reverse a string, palindrome, vowel and word count, character frequency, plus string interview questions.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/smitabharat.com\/blog\/go-string-programs\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Go String Programs: Reverse, Palindrome, Count\" \/>\n<meta property=\"og:description\" content=\"Go string programs with output: reverse a string, palindrome, vowel and word count, character frequency, plus string interview questions.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/smitabharat.com\/blog\/go-string-programs\/\" \/>\n<meta property=\"og:site_name\" content=\"Smita Bharat - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-05T09:30:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-11-28T19:59:39+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-string-programs-featured.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Smita\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Smita\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"17 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-string-programs\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-string-programs\\\/\"},\"author\":{\"name\":\"Smita\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"headline\":\"Go String Programs with Output: Reverse, Palindrome, Count\",\"datePublished\":\"2026-10-05T09:30:00+00:00\",\"dateModified\":\"2026-11-28T19:59:39+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-string-programs\\\/\"},\"wordCount\":1871,\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-string-programs\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-string-programs-featured.png\",\"keywords\":[\"Beginner\",\"Go Interview Questions\",\"Go Lang\",\"Go Programs\",\"Go Strings\"],\"articleSection\":[\"Go Programs\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-string-programs\\\/\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-string-programs\\\/\",\"name\":\"Go String Programs: Reverse, Palindrome, Count\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-string-programs\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-string-programs\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-string-programs-featured.png\",\"datePublished\":\"2026-10-05T09:30:00+00:00\",\"dateModified\":\"2026-11-28T19:59:39+00:00\",\"description\":\"Go string programs with output: reverse a string, palindrome, vowel and word count, character frequency, plus string interview questions.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-string-programs\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-string-programs\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-string-programs\\\/#primaryimage\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-string-programs-featured.png\",\"contentUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-string-programs-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Go String Programs featured image: reverse, palindrome and count output\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-string-programs\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Go String Programs with Output: Reverse, Palindrome, Count\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\",\"name\":\"Smita Bharat Blog\",\"description\":\"Golang &amp; Backend Development Tutorials and Interview Questions\",\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"alternateName\":\"Smita Bharat\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\",\"name\":\"Smita\",\"logo\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/smitabharat.com\\\/blog\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Go String Programs: Reverse, Palindrome, Count","description":"Go string programs with output: reverse a string, palindrome, vowel and word count, character frequency, plus string interview questions.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/smitabharat.com\/blog\/go-string-programs\/","og_locale":"en_US","og_type":"article","og_title":"Go String Programs: Reverse, Palindrome, Count","og_description":"Go string programs with output: reverse a string, palindrome, vowel and word count, character frequency, plus string interview questions.","og_url":"https:\/\/smitabharat.com\/blog\/go-string-programs\/","og_site_name":"Smita Bharat - Blog","article_published_time":"2026-10-05T09:30:00+00:00","article_modified_time":"2026-11-28T19:59:39+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-string-programs-featured.png","type":"image\/png"}],"author":"Smita","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Smita","Est. reading time":"17 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/smitabharat.com\/blog\/go-string-programs\/#article","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/go-string-programs\/"},"author":{"name":"Smita","@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"headline":"Go String Programs with Output: Reverse, Palindrome, Count","datePublished":"2026-10-05T09:30:00+00:00","dateModified":"2026-11-28T19:59:39+00:00","mainEntityOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-string-programs\/"},"wordCount":1871,"publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-string-programs\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-string-programs-featured.png","keywords":["Beginner","Go Interview Questions","Go Lang","Go Programs","Go Strings"],"articleSection":["Go Programs"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/smitabharat.com\/blog\/go-string-programs\/","url":"https:\/\/smitabharat.com\/blog\/go-string-programs\/","name":"Go String Programs: Reverse, Palindrome, Count","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-string-programs\/#primaryimage"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-string-programs\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-string-programs-featured.png","datePublished":"2026-10-05T09:30:00+00:00","dateModified":"2026-11-28T19:59:39+00:00","description":"Go string programs with output: reverse a string, palindrome, vowel and word count, character frequency, plus string interview questions.","breadcrumb":{"@id":"https:\/\/smitabharat.com\/blog\/go-string-programs\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/smitabharat.com\/blog\/go-string-programs\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/smitabharat.com\/blog\/go-string-programs\/#primaryimage","url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-string-programs-featured.png","contentUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-string-programs-featured.png","width":2400,"height":1260,"caption":"Go String Programs featured image: reverse, palindrome and count output"},{"@type":"BreadcrumbList","@id":"https:\/\/smitabharat.com\/blog\/go-string-programs\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/smitabharat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Go String Programs with Output: Reverse, Palindrome, Count"}]},{"@type":"WebSite","@id":"https:\/\/smitabharat.com\/blog\/#website","url":"https:\/\/smitabharat.com\/blog\/","name":"Smita Bharat Blog","description":"Golang &amp; Backend Development Tutorials and Interview Questions","publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"alternateName":"Smita Bharat","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/smitabharat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339","name":"Smita","logo":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/smitabharat.com\/blog"]}]}},"_links":{"self":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/775","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/comments?post=775"}],"version-history":[{"count":1,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/775\/revisions"}],"predecessor-version":[{"id":877,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/775\/revisions\/877"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media\/774"}],"wp:attachment":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media?parent=775"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/categories?post=775"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/tags?post=775"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=775"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}