Golang StringsExplore the strings package. The methods in strings create, test and modify string data.
Strings. Text data is everywhere. It is in files, user input, on websites. A language's ability to create and manipulate strings is critical. This is a common task.
We can specify string literals in Golang with 2 different syntax forms. Raw string literals (with tick chars) should be used if escaped chars need to be encoded.String Literal
There is no Substring() method to take ranges of characters in Go. Instead we use the slice syntax (with first and last indexes).Substring
Rune slice: For substrings, we often want to use rune slices. It is easy to convert a string into a rune slice in Golang.Convert String, Rune Slice
We can translate strings based on characters in Go. We apply the strings.Map method to implement ciphers like ROT13, which rotates characters.
Caesar: This cipher shifts characters by a certain number of characters. It has historical significance.Caesar Cipher
ROT13: This cipher rotates characters by 13 places (which explains the name). It is sometimes used to make text harder to read.ROT13
To reverse a string, we must access it at the level of runes or bytes. Reversing a string helps us learn how to manipulate the contents of strings.Reverse String
In the strings package, which we specify in an import block, we gain access to many funcs. Things like replacing string data, changing cases, and removing whitespace are easy.
Many string-based methods are implemented with the "strings" package. But often we can use rune slices to modify strings. This functionality is built into Go.
Quote: Package strings implements simple functions to manipulate strings.Strings: golang.org
String usage. In programming strings are everywhere. We use them constantly. With the powerful and complete set of funcs in the strings package, we can use them with ease.
© 2007-2020 Sam Allen. Every person is special and unique. Send bug reports to firstname.lastname@example.org.