Golang How to Write Multiline String
If you have newlines in a string you will face an error! The simple solution is using backtick (`) around your string: Another way to… Read More »Golang How to Write Multiline String
If you have newlines in a string you will face an error! The simple solution is using backtick (`) around your string: Another way to… Read More »Golang How to Write Multiline String
Ok, we have a huge amount of strings to join them to each other! and maybe from different types! To concatenate strings efficiently my recommendation… Read More »Golang Concatenate Strings [Efficient Way – Builder]
If you want to simply replace a string then golang has a fantastic function Replace from strings package for you: If n < 0, there… Read More »How to Replace a Substring in a String in Golang?
If you want to simply remove the leading and trailing white spaces from a string then forget about the regex and only use TrimSpace simple… Read More »Golang: How to Trim Whitespace and Newlines
This is the easiest thing I want to mention! Just use the equal (==) operator in golang: Code example:
Just call the HasPrefix function from the lovely strings package: Simple example code to check if a list of strings has a prefix:
Checking if a character or a substring exists in a string is so simple: And a simple example:
In Golang convert an object to JSON string (or a slice of bytes) is so simple by using the json package: In this example you… Read More »Golang: Simple Marshal Struct to JSON
If you want to work with a piece of string in Golang then your best friend is strings package! The split function can convert a… Read More »How to Split a String Into a Slice and Join Them Back [Golang]