It looks like you're confused by the working of slices and the string storage format, which is different from what you have in C.

  • any slice in Go stores the length (in bytes), so you don't have to care about the cost of the len operation : there is no need to count
  • Go strings aren't null terminated, so you don't have to remove a null byte, and you don't have to add 1 after slicing by adding an empty string.

To remove the last char (if it's a one byte char), simply do

inputFmt:=input[:len(input)-1]
Answer from Denys Séguret on Stack Overflow
🌐
Go Packages
pkg.go.dev › strings
strings package - strings - Go Packages
Fields splits the string s around each instance of one or more consecutive white space characters, as defined by unicode.IsSpace, returning a slice of substrings of s or an empty slice if s contains only white space. Every element of the returned slice is non-empty.
🌐
Golang Docs
golangdocs.com › home › substring in golang
Substring in Golang - Golang Docs
March 9, 2020 - This method returns an array of substrings generated from all of the splits using that character.
🌐
TutorialsPoint
tutorialspoint.com › go › go_substring_extraction.htm
Go - Substring Extraction
In Golang, a substring is a portion of a larger string. It is specified by providing a start index and a length, and it contains the characters of the original string starting at the start index and going up to the specified length.
🌐
Leapcell
leapcell.io › blog › extracting-substrings-in-go
Extracting Substrings in Go | Leapcell
July 25, 2025 - In Go, extracting substrings can be achieved using slices and the strings package.
Find elsewhere
🌐
Scaler
scaler.com › home › topics › golang › what is a substring in golang?
What is a Substring in Golang? - Scaler Topics
May 4, 2023 - Golang Substring is a part of the string in the Go language. It refers to the characters in a sequence that are contained within the larger set of the string. In most cases, a part of the string is to be extracted.
🌐
Bacancy Technology
bacancytechnology.com › qanda › golang › extracting-substrings-in-go
Simplify Extracting Substrings in Go | Expert Insights
Whether you’re using simple slicing, the strings package, strings.Split, or regular expressions, Go provides powerful tools to make substring extraction efficient and expressive. Choose the method that best fits your specific use case, and leverage Go’s simplicity and readability to work with strings effectively in your programs. Work with our skilled Golang developers to accelerate your project and boost its performance.
🌐
Educative
educative.io › answers › how-to-count-a-substrings-occurrence-in-a-string-in-go
How to count a substring's occurrence in a string in Go
The string package provides the Count() method, which can be used to count the number of times a non-overlapping instance of a substring appears in a string in Go.
🌐
Admfactory
admfactory.com › home › strings functions in golang
Strings functions in Golang | ADMFactory
April 19, 2020 - Some of the most used functions are: strings.Compare: takes two string arguments. The result will be 0 if a==b, -1 if a < b, and +1 if a > b. strings.Contains: returns whether the second parameter can be found as substring in the first parameter.
🌐
Roadmap
roadmap.sh › leetcode
LeetCode
April 15, 2026 - Step-by-step guide to pass your coding interview · roadmap.sh is the 6th most starred project on GitHub and is visited by hundreds of thousands of developers every month
🌐
Go
go.dev › play › p › x9UMI3eTfS
Go Playground - The Go Programming Language
Any requests for content removal should be directed to security@golang.org.
🌐
GitHub
gist.github.com › yuchan › 2857491
Substring #GoLang · GitHub
Substring #GoLang. GitHub Gist: instantly share code, notes, and snippets.
🌐
Boot.dev
boot.dev › blog › golang › how replace a string in go - top 5 examples
How Replace a String in Go - Top 5 Examples | Boot.dev
October 1, 2022 - Go has a powerful standard library that makes string manipulation easy right out of the box. One of the functions I use most often is the strings package's Replace() function. strings.Replace() returns a copy of its input string after replacing all instances of a given substring with a new one.
🌐
TutorialsPoint
tutorialspoint.com › article › how-to-check-if-a-string-contains-a-substring-in-golang
How to check if a string contains a substring in Golang?
February 21, 2022 - We know that substrings are a contiguous sequence of characters in a string, and in order to check whether a string contains a substring, we have two options available. The first approach is to use a built-in function called Contains() and the