
Working with strings in Golang is a fundamental aspect of programming, and it's essential to understand the basics. You can create a string in Golang by enclosing a sequence of characters in double quotes, like this: "Hello, World!".
Strings in Golang are immutable, meaning they cannot be changed after creation. This is a deliberate design choice to prevent unexpected behavior in multithreaded environments.
Golang's strings are also a type of byte slice, which means they can be manipulated like arrays of bytes. This is useful for tasks like encoding and decoding data.
Strings in Golang can be concatenated using the + operator, or the fmt.Sprintf function. For example, "Hello, " + "World!" or fmt.Sprintf("Hello, %s!", "World").
Broaden your view: Helloworld Golang
String Operations
String operations in Go are a breeze with the built-in functions. Join concatenates the elements of its first argument to create a single string, placing the separator string between elements.
You can use Join to create a comma-separated list of values, for instance. The separator string can be anything, not just a comma.
You might like: Golang String to Time
The Replace function returns a copy of the string with the first n non-overlapping instances of old replaced by new. If old is empty, it matches at the beginning of the string and after each UTF-8 sequence.
This makes Replace particularly useful for removing duplicates or unwanted characters from a string. If n < 0, there is no limit on the number of replacements, giving you even more flexibility.
The Split function slices s into all substrings separated by sep and returns a slice of the substrings between those separators. If sep is empty, Split splits after each UTF-8 sequence.
Broaden your view: Declate a Map of String and Value as Map Golang
Contains
The Contains function is a handy tool for checking if a substring exists within a string. It's a simple yet powerful operation that can be used in a variety of scenarios.
You can use Contains to report whether a specific substring is present in a string, as seen in the example "func Contains¶ Contains reports whether substr is within s."
This function is useful when you need to check if a certain word or phrase is contained within a larger string. For instance, you might want to verify if a specific keyword is present in a piece of text.
There are multiple variants of the Contains function, including ContainsRune, which checks if a single Unicode code point is present in a string. This can be useful when working with specific characters or symbols.
The ContainsAny function takes it a step further by checking if any Unicode code points in a given set are present in a string. This can be particularly useful when working with strings that contain a mix of characters.
In some cases, you might need to find the last instance of a character in a string. That's where the LastIndexByte function comes in, which returns the index of the last instance of a character in a string, or -1 if it's not present.
Readers also liked: Golang Func Type
Join

The Join function is a powerful tool for combining strings. It concatenates the elements of its first argument to create a single string.
The separator string sep is placed between elements in the resulting string, which can be a comma, a space, or any other character you need.
Map
The Map function is a powerful tool for modifying strings. It returns a copy of the string with all its characters modified according to the mapping function.
The mapping function is where the magic happens, and it's up to you to define how each character is transformed. If you return a negative value, the character is dropped from the string with no replacement.
You can use Map to create a new string with modified characters, without altering the original string. This is especially useful when you need to perform complex string transformations.
For example, if you want to remove all vowels from a string, you can use a mapping function that returns a negative value for each vowel character. The resulting string will have all vowels removed.
Map is a versatile function that can be used in a wide range of string operations. By defining a mapping function that suits your needs, you can create a new string with the desired characteristics.
A unique perspective: Golang Use .env File
Repeat
The Repeat function is a useful tool for creating new strings by duplicating existing ones.
It takes two parameters: a string s and an integer count.
The function returns a new string consisting of count copies of the string s.
The Repeat function panics if the count is negative.
If the result of (len(s) * count) overflows, the function also panics.
This means you need to be mindful of the size of the string and the number of copies you're trying to make.
Remove
The Map function can be used to remove characters from a string by returning a negative value, effectively dropping the character with no replacement.
If you have a string with unwanted characters and you want to remove them, you can use the Map function in combination with a mapping function that returns a negative value for the unwanted characters.
The Replace function can be used to remove a substring from a string by replacing it with an empty string.
Split

Split is a string operation that divides a slice into substrings separated by a specified separator. It returns a slice of the substrings between those separators.
If the input string doesn't contain the separator and it's not empty, Split returns a slice of length 1 with the original string as its only element.
Split splits after each UTF-8 sequence if the separator is empty. This is a useful feature for working with strings that contain multiple languages.
If both the input string and the separator are empty, Split returns an empty slice. This makes sense, as there's nothing to split in that case.
Split is equivalent to SplitN with a count of -1. This means you can use either function to achieve the same result, depending on your personal preference or the specific use case.
To split a string around the first instance of a separator, you should use Cut instead of Split.
Suggestion: Golang Use Cases
After
After removing unwanted parts from a string, you're left with a new string that's been trimmed. The Trim function returns a slice of the original string with all leading and trailing Unicode code points in the cutset removed. This is a powerful tool for cleaning up strings.
For example, if you have a string with leading and trailing whitespace, you can use Trim to remove it. The TrimPrefix function, on the other hand, removes a specific prefix from the start of a string. If the string doesn't start with the prefix, it's returned unchanged. This is useful when you need to remove a consistent prefix from a series of strings.
TrimSuffix is similar to TrimPrefix, but it removes a suffix from the end of a string. If the string doesn't end with the suffix, it's returned unchanged. This is particularly useful when working with file paths or URLs.
Readers also liked: T Golang
To Title Special
ToTitleSpecial is a useful function for mapping Unicode letters to their title case, but it's not the only option. ToTitleSpecial returns a copy of the string s with all Unicode letters mapped to their Unicode title case, giving priority to the special casing rules.
The special casing rules are what set ToTitleSpecial apart from other title case functions. This function takes into account specific rules for handling certain characters, making it a more accurate choice for certain use cases.
One thing to keep in mind is that ToTitleSpecial is not a replacement for every other title case function. It's specifically designed to give priority to special casing rules, which may not be necessary for every string operation.
Clone
Clone is a function that returns a fresh copy of a string.
Using Clone can help programs use less memory by making a copy of a small substring of a much larger string.
However, overusing Clone can make programs use more memory because it makes a copy of the string.
Clone should be used only rarely, and only when profiling indicates that it is needed.
For strings of length zero, Clone returns the string "" and no allocation is made.
1.5
In the 1.5 release, the ingo package introduced two new string operations: LastIndexByte and Compare.
LastIndexByte returns the index of the last instance of a byte in a string, or -1 if the byte is not present. This is useful when you need to find the last occurrence of a character in a string.
The Compare function returns an integer comparing two strings lexicographically. It's usually faster and clearer to use the built-in string comparison operators, but Compare is useful when you need to perform a three-way comparison.
String Methods
String Methods are a crucial part of working with strings in Go. The ContainsRune method reports whether a specific Unicode code point is within a string.
You can use ContainsRune to check for the presence of a particular character in a string. This is useful for validating user input or searching for specific patterns in text data.
For example, you might use ContainsRune to verify that a username contains a certain character, such as an "@" symbol.
Contains Rune
The ContainsRune function is a useful tool in Go. It reports whether a specific Unicode code point is within a given string.
This function is similar to Contains, but it takes a rune (an alias for int32) as an argument, rather than a string. The ContainsRune function is useful when you need to check if a specific character is present in a string.
To use ContainsRune, you simply pass in the string and the Unicode code point you're looking for, and it will return a boolean indicating whether the code point is present.
You might like: Golang Comments
Len
The Len method is a useful tool for checking the length of a string in Go. It returns the number of accumulated bytes.
You can use Len to get the length of a Builder object, which is the number of bytes it has accumulated. This is useful for tracking progress or checking the size of a string.
The Len method is available in Go 1.10 and later versions. If you're using an earlier version, you'll need to upgrade to use this method.
One thing to keep in mind is that Len returns the number of bytes, not the number of characters. This is because Go strings can contain characters that are represented by multiple bytes. For example, a string containing an emoji will have a longer byte length than a string containing a single letter.
The Len method can be used with the String method to check the length of a string. The String method returns the actual string value, and you can use Len to get its length. For example, b.Len() == len(b.String()).
Related reading: Golang Go
Left

TrimLeft returns a slice of the string s with all leading Unicode code points contained in cutset removed.
You can use TrimLeft to remove unwanted characters from the beginning of a string. For example, if you have a string with extra whitespace, you can use TrimLeft to remove it.
To remove a prefix, use TrimPrefix instead. This is a more specific function that's better suited for removing a specific string from the beginning of another string.
TrimLeftFunc returns a slice of the string s with all leading Unicode code points c satisfying f(c) removed. This function is similar to TrimLeft, but it uses a function to determine which characters to remove.
TrimLeftFunc is useful when you need to remove characters based on a specific condition. For example, if you want to remove all leading vowels from a string, you can use TrimLeftFunc with a function that returns true for vowels and false otherwise.
Explore further: Golang Source Code
To Lower
The ToLower method is a string method that's super useful for making text lowercase. It takes a string s and returns a new string with all Unicode letters mapped to their lower case.
You can use ToLower to make a string more readable or to ensure consistency in your text. For instance, if you have a string with a mix of uppercase and lowercase letters, ToLower will convert it to all lowercase.
There are actually two versions of ToLower, which are almost identical. The first one, ToLower, simply returns a new string with all Unicode letters mapped to their lower case. The second one, ToLowerSpecial, does the same thing but uses a specific case mapping specified by c.
The ToLower method is case-sensitive, so it will treat uppercase and lowercase letters as different characters. This means that if you have a string with a mix of uppercase and lowercase letters, ToLower will preserve the original case of the letters.
WriteRune in 1.10
In Go, strings are actually slices of bytes, but when you range over a string, you get a rune, not a byte. A rune is an alias for int32, which is why you get an int32 value in your program.
Ranging over a string gives you a rune, not a byte, because runes are the fundamental units of text in Go. They represent a single Unicode code point, which can be a single byte, multiple bytes, or even an invalid UTF-8 byte sequence.
The WriteRune function in Go's net/textproto package has been updated to append the UTF-8 encoding of a Unicode code point to a buffer. This function is particularly useful for building strings incrementally in Go.
You can use the WriteRune function to write a single rune to a buffer, and it returns the length of the written rune and a nil error. This makes it easy to build strings one rune at a time.
A fresh viewpoint: Go vs Golang
String Validation
String Validation is a crucial aspect of working with strings in Go. The `ToValidUTF8` function is available in Go 1.13 and later.
It replaces invalid UTF-8 byte sequences with a replacement string, which can be empty. This ensures that your program can handle strings with invalid UTF-8 byte sequences.
You can use `ToValidUTF8` to create a copy of a string with invalid UTF-8 byte sequences replaced. This function is particularly useful when working with user input or external data that may contain invalid UTF-8 byte sequences.
Has
The "Has" keyword is used for string validation to check if a string contains a specific substring.
In a regular expression, the "Has" keyword is used to match a string that contains a specific substring. For example, the regular expression "has 'hello'" will match any string that contains the substring "hello".
This keyword is useful for checking if a string meets certain criteria, such as containing a specific word or phrase.
In the example "has 'abc'", the regular expression will match any string that contains the substring "abc".
Valid UTF8 in 1.13
In Go 1.13, the ToValidUTF8 function was added to ensure strings are in a valid UTF-8 format.
This function returns a copy of the input string with each run of invalid UTF-8 byte sequences replaced by the replacement string, which can be empty.
The replacement string can be used to replace invalid byte sequences with a default value, such as a placeholder or a question mark.
ToValidUTF8 is useful for handling strings that may contain invalid UTF-8 byte sequences, which can occur when working with text data from unknown sources.
By using ToValidUTF8, you can ensure that your strings are in a valid UTF-8 format, which is essential for proper text encoding and decoding.
If this caught your attention, see: Golang Time Formats
String Builders
String Builders are a crucial part of working with strings in Go.
You can use the WriteString method to append the contents of a string to a buffer. This method was added in Go 1.10.
It's worth noting that WriteString returns the length of the string and a nil error.
String Readers
A Reader in Go is a powerful tool for working with strings. It implements multiple interfaces, including io.Reader, io.ReaderAt, io.ByteReader, io.ByteScanner, io.RuneReader, io.RuneScanner, io.Seeker, and io.WriterTo, making it a versatile solution for reading from a string.
The zero value for a Reader is an empty string. This means that a new Reader will behave like it's reading from an empty string until you assign it a value.
In practice, this means you can create a Reader from any string, and it will be ready to use. For example, you could create a Reader from a variable that holds a string, or even a string literal.
Suggestion: Golang Io
WriteRune1.10
The WriteRune function is a crucial tool for any string reader. It appends the UTF-8 encoding of a Unicode code point to a buffer, which is a sequence of bytes used to store data.
The WriteRune function returns the length of the appended Unicode code point and a nil error, indicating that the operation was successful.
As a string reader, you can use WriteRune to write a single Unicode code point to a buffer. The function takes a single argument, the Unicode code point to be written, and returns the length of the written code point and an error.
The WriteRune function is particularly useful when working with Unicode characters that have multiple bytes in their UTF-8 encoding. It allows you to write these characters to a buffer without having to manually handle the byte encoding.
Readers also liked: Golang Os Write File
Type Reader
A Reader in Go is a versatile and efficient way to read data from a string. It implements several interfaces, including io.Reader, io.ReaderAt, io.ByteReader, io.ByteScanner, io.RuneReader, io.RuneScanner, io.Seeker, and io.WriterTo.
This means a Reader can be used in a variety of contexts, from reading individual bytes to scanning for runes. The zero value for a Reader operates like a Reader of an empty string.
This is important to note because it means that if you don't initialize a Reader, it will default to reading from an empty string. This can be useful in certain situations where you want to handle an empty string as a special case.
String Comparison
String comparison in Go can be done in a few ways. The EqualFold function reports whether two strings are equal under simple Unicode case-folding, making it a more general form of case-insensitivity.
You can use EqualFold to compare strings in a case-insensitive manner. For example, it would return true for "Hello" and "hELLO". The EqualFold function is useful when you need to compare strings in a way that ignores case differences.
The Compare function returns an integer comparing two strings lexicographically. This means it compares strings character by character, returning 0 if they're equal, -1 if one is less than the other, and +1 if one is greater than the other. This is useful when you need to perform a three-way comparison, like when sorting a list of strings.
Equal Fold
Equal Fold is a powerful way to compare strings in a case-insensitive manner. It interprets strings as UTF-8 strings and checks for equality under simple Unicode case-folding.
Intriguing read: Switch Statement Golang
This form of case-insensitivity is more general than traditional case-insensitivity, making it a valuable tool for string comparison. Equal Fold can help you avoid issues with strings that have different cases but are otherwise identical.
To use Equal Fold, you need to know that it reports whether two strings are equal under the specified case-folding rules.
Right
When working with strings, it's essential to understand how to trim them effectively.
TrimRight returns a slice of the string s, with all trailing Unicode code points contained in cutset removed.
Trimming strings can be a bit tricky, but it's a crucial step in many programming tasks.
TrimRightFunc returns a slice of the string s with all trailing Unicode code points c satisfying f(c) removed.
I've encountered situations where I needed to remove specific characters from the end of a string, and TrimRightFunc came to the rescue.
Cutset is a term used to describe the set of characters that will be removed by TrimRight.
The key difference between TrimRight and TrimRightFunc is that TrimRightFunc allows for more flexibility in defining the characters to be removed.
Compare 1.5

Compare 1.5 is a function that returns an integer comparing two strings lexicographically. The result will be 0 if the strings are equal, -1 if the first string is less than the second, and +1 if the first string is greater than the second.
It's usually clearer and always faster to use the built-in string comparison operators, but Compare can be useful when you need to perform a three-way comparison.
Compare is often used with slices.SortFunc, which sorts a slice of strings based on the comparison function.
Replace
The Replace function is a powerful tool for manipulating strings in Go. It returns a copy of the string with the first n non-overlapping instances of old replaced by new.
If old is empty, it matches at the beginning of the string and after each UTF-8 sequence, yielding up to k+1 replacements for a k-rune string.
You can think of this as replacing all occurrences of a substring, but with a twist: if the old string is empty, it matches at every possible location in the string.
If n is less than 0, there is no limit on the number of replacements, allowing you to replace every instance of old with new.
The (*Replacer) Replace function is similar, but it returns a copy of s with all replacements performed.
String Lines
String lines can be tricky to work with, especially when it comes to handling newline characters.
The Lines function in Go returns an iterator over the newline-terminated lines in a given string.
If a string is empty, the iterator will yield no lines at all.
The iterator includes the terminating newlines in the lines it yields.
If a string doesn't end in a newline, the final yielded line will not end in a newline.
A Lines iterator is a single-use iterator, meaning you can only use it once before it's exhausted.
String Fields
FieldsFunc splits the string s at each run of Unicode code points c satisfying f(c) and returns an array of slices of s.
If all code points in s satisfy f(c) or the string is empty, FieldsFunc returns an empty slice.
Every element of the returned slice is non-empty.
FieldsFunc makes no guarantees about the order in which it calls f(c) and assumes that f always returns the same value for a given c.
FieldsFuncSeq returns an iterator over substrings of s split around runs of Unicode code points satisfying f(c).
The iterator yields the same strings that would be returned by FieldsFunc(s), but without constructing the slice.
Space

Trimming down to the basics, you can use the TrimSpace function to remove leading and trailing white space from a string. This function returns a slice of the original string with the unwanted space removed.
The TrimSpace function defines white space according to Unicode standards. This means it will remove not just the spaces you see, but also other types of whitespace characters like tabs and line breaks.
You can use TrimSpace to clean up strings that have extra space at the beginning or end. For example, if you have a string like " hello world ", TrimSpace would return "hello world".
Fields
Fields is a way to split a string into substrings based on specific criteria.
You can use FieldsFunc to split a string at each run of Unicode code points that satisfy a given function f(c).
This function returns an array of slices of the original string, but discards leading and trailing runs of code points that satisfy f(c).

FieldsFunc makes no guarantees about the order in which it calls f(c), and assumes that f always returns the same value for a given c.
If all code points in the string satisfy f(c) or the string is empty, FieldsFunc returns an empty slice.
Every element of the returned slice is non-empty.
FieldsFuncSeq is similar to FieldsFunc, but returns an iterator over substrings instead of constructing the slice.
This iterator yields the same strings as FieldsFunc, but without creating a new array.
FieldsSeq is another way to split a string into substrings, but it specifically splits around runs of whitespace characters.
It returns an iterator over the substrings, similar to FieldsFuncSeq.
String Suffix
The CutSuffix function returns a string without a provided ending suffix string and reports whether it found the suffix.
If the string s doesn't end with the suffix, CutSuffix returns the original string s, false. If the suffix is the empty string, CutSuffix returns the original string s, true.
You can use the HasSuffix function to check if a string ends with a specific suffix.
The TrimSuffix function removes a trailing suffix string from a string s, returning the modified string if the suffix is found, and the original string if it's not.
If you try to remove a suffix that's not present, TrimSuffix will simply return the original string, unchanged.
String Conversions
You can explicitly convert a string value to a byte slice, and vice versa, which is useful for working with binary data. This conversion is a slice with an element type's underlying type as []byte.
A string value can also be explicitly converted to a rune slice, and vice versa. This conversion is a slice whose element type's underlying type as []rune.
Note that illegal UTF-8 encoded bytes are allowed and will keep unchanged during these conversions.
Here are some ways to convert between strings and byte slices:
- Use string values as a hop, but this method is not very efficient as two deep copies are needed.
- Use the functions in the unicode/utf8 standard package.
- Use the Runes function in the bytes standard package to convert a []byte value to a []rune value.
UTF-8 1.13
UTF-8 1.13 has a function called ToValidUTF8 that returns a copy of a string with each run of invalid UTF-8 byte sequences replaced by a specified replacement string, which can be empty.

This function is useful for handling strings that may contain invalid UTF-8 byte sequences, which can cause issues with certain operations.
ToValidUTF8 is added in Go version 1.13.
You can use this function to ensure that all strings in your program are valid UTF-8, which can make your code more robust and easier to work with.
This function returns a new string with the invalid byte sequences replaced, but it does not modify the original string.
Related Conversions
String conversions can be a bit tricky, but don't worry, I'm here to help. You can explicitly convert a string value to a byte slice, and vice versa, which is useful when working with binary data.
A byte slice is a slice with an element type of []byte, and a rune slice is a slice whose element type's underlying type is []rune. This means you can easily switch between these two types.
If you have illegal UTF-8 encoded bytes, they'll be allowed and kept unchanged. This might not be ideal, but it's something to be aware of.

To optimize string conversions, the Go compiler makes some special cases that avoid deep copies. These cases will be introduced below.
There are a few ways to convert between string and byte/rune slices. One way is to use string values as a hop, but this can be inefficient as it requires two deep copies. A better approach is to use the functions in the unicode/utf8 standard package.
The bytes standard package also provides a convenient way to convert between byte and rune slices using the Runes function. However, there isn't a function to convert a rune slice to a byte slice in this package.
Here are some options to convert between string and byte/rune slices:
- Use string values as a hop (but be aware of the inefficiency)
- Use the functions in the unicode/utf8 standard package
- Use the Runes function in the bytes standard package (but note the lack of a rune-to-byte function)
Empty String Equals Zero
In programming, the concept of zero values is crucial, especially when working with strings. The zero value of a string is an empty string.
When you're dealing with strings, it's essential to remember that an empty string is never nil. This means that an empty string can't be converted to nil, unlike other types of values.
In some programming languages, types can vary, but in this context, the type of each value is int32, which is a specific type of integer.
1.20
In Go, the 1.20 version introduced two new functions that can be super helpful when working with strings.
CutSuffix returns s without the provided ending suffix string and reports whether it found the suffix.
If s doesn't end with suffix, CutSuffix returns s, false. If suffix is the empty string, CutSuffix returns s, true.
CutPrefix returns s without the provided leading prefix string and reports whether it found the prefix.
1.24
In Go, version 1.24 introduced several string conversion functions that make working with strings more efficient. These functions return iterators over substrings, rather than constructing slices.
FieldsFuncSeq returns an iterator over substrings of s split around runs of Unicode code points satisfying f(c). This is similar to FieldsFunc, but without constructing the slice.
SplitSeq returns an iterator over all substrings of s separated by sep, yielding the same strings as Split(s, sep) without constructing the slice. It's a single-use iterator, so use it once and discard it.
SplitAfterSeq returns an iterator over substrings of s split after each instance of sep, similar to SplitAfter(s, sep) without constructing the slice. Like SplitSeq, it's a single-use iterator.
Lines returns an iterator over the newline-terminated lines in the string s, including their terminating newlines. If s is empty, the iterator yields no lines at all.
FieldsSeq returns an iterator over substrings of s split around runs of whitespace characters, as defined by unicode.IsSpace. This is similar to Fields(s), but without constructing the slice.
On a similar theme: Golang Copy Slice
String Type
In Go, strings are a sequence of bytes, not characters, which is a key difference from other programming languages.
Strings are immutable, meaning their contents cannot be changed after creation.
Go's strings are not null-terminated, unlike C-style strings.
The length of a string in Go can be determined using the built-in len() function.
Strings can be created using the string literal syntax, such as "hello" or 'hello'.
The + operator can be used to concatenate two strings together.
String Functions
In Go, strings are immutable, meaning once a string is created, it cannot be changed.
You can use the len() function to get the length of a string, for example, len("hello") returns 5.
The strings package in Go provides various functions for manipulating strings, such as TrimSpace() and ToTitle().
These functions can be used to clean up user input or format strings for output.
Count
The Count function is a useful tool for counting non-overlapping instances of a substring in a string. It's simple to use and gives you an accurate count.
If you try to count an empty string, the Count function will return 1 plus the number of Unicode code points in the string. This is a key thing to keep in mind when using the function.
The Count function is great for tasks like counting words or characters in a string.
String Overview
The golang strings package is designed to work with UTF-8 encoded strings. This means you can use it to manipulate strings that contain a wide range of characters from different languages.
The package implements simple functions for string manipulation, which makes it easy to use.
UTF-8 encoding is a variable-length character encoding standard that is widely used for web pages and other digital content.
Consider reading: Install Golang Package
String Documentation
The Lines function returns an iterator over the newline-terminated lines in a given string. The iterator includes the terminating newlines, but if the string is empty, the iterator yields no lines at all.
The Lines function is a useful tool for processing text data, such as reading a file line by line. If you're working with a string that doesn't end in a newline, the final yielded line will not have a newline at the end.
Here's a list of the string manipulation functions available in Go:
- Builder
- Clone
- Compare
- Contains
- ContainsAny
- ContainsFunc
- ContainsRune
- Count
- Cut
- CutPrefix
- CutSuffix
- EqualFold
- Fields
- FieldsFunc
- FieldsFuncSeq
- FieldsSeq
- HasPrefix
- HasSuffix
- Index
- IndexAny
- IndexByte
- IndexFunc
- IndexRune
- Join
- LastIndex
- LastIndexAny
- LastIndexByte
- LastIndexFunc
- Lines
- Map
- NewReplacer
- Repeat
- Replace
- ReplaceAll
- Split
- SplitAfter
- SplitAfterN
- SplitAfterSeq
- SplitN
- SplitSeq
- Title
- ToLower
- ToLowerSpecial
- ToTitle
- ToTitleSpecial
- ToUpper
- ToUpperSpecial
- ToValidUTF8
- Trim
- TrimFunc
- TrimLeft
- TrimLeftFunc
- TrimPrefix
- TrimRight
- TrimRightFunc
- TrimSpace
- TrimSuffix
The Lines function returns a single-use iterator, so be sure to process the lines before the iterator is exhausted.
String Version
NewReplacer returns a new Replacer from a list of old, new string pairs. The replacements are performed in the order they appear in the target string, without overlapping matches.
The old string comparisons are done in argument order, which means the first old string is compared first, the second old string is compared second, and so on. This is an important consideration when creating your list of old, new string pairs.
NewReplacer panics if given an odd number of arguments, so be sure to provide an even number of arguments to avoid a panic.
See what others are reading: Golang Command Line Arguments
Write1.10

Write1.10 is a method that allows you to append the contents of a string to a buffer. It returns the length of the string and a nil error.
If you're working with strings in version 1.10, you'll likely use WriteString. This method is a key part of the Builder type, which is used for building strings.
The WriteString method takes a string as an argument and appends its contents to the buffer. It's a simple yet powerful tool for working with strings.
In practice, WriteString is often used in conjunction with other methods to build and manipulate strings. It's a fundamental part of the string handling functionality in version 1.10.
Check this out: Golang Version Manager
New
New strings can be created using the Clone function, which makes a fresh copy of a string and guarantees a new allocation. This can be important for programs that need to retain only a small substring of a much larger string.
Clone returns a string of length zero as an empty string "".
Using Clone can help programs use less memory, but overuse of Clone can make programs use more memory.
The Clone function should typically be used only rarely, and only when profiling indicates that it is needed.
All 1.12

String Version 1.12 is a significant update that brings several key improvements to the way strings are handled in your code. It introduces a new function called ReplaceAll, which returns a copy of the string s with all non-overlapping instances of old replaced by new.
One of the most interesting aspects of ReplaceAll is that it can make up to k+1 replacements for a k-rune string, depending on the length of the old string. This can be a game-changer for certain types of string manipulation.
ReplaceAll is also clever about handling empty old strings. If old is empty, it matches at the beginning of the string and after each UTF-8 sequence, which can lead to some unexpected but useful behavior.
In practice, I've found that ReplaceAll is a powerful tool for simplifying complex string manipulation tasks. By leveraging its ability to make multiple replacements at once, you can write more concise and efficient code that's easier to maintain.
Featured Images: pexels.com


