https://github.com/lusingander/sasa
String utilities for Go 🎋
https://github.com/lusingander/sasa
go string
Last synced: about 2 months ago
JSON representation
String utilities for Go 🎋
- Host: GitHub
- URL: https://github.com/lusingander/sasa
- Owner: lusingander
- License: mit
- Created: 2023-09-18T01:19:51.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-12-26T00:36:21.000Z (about 1 year ago)
- Last Synced: 2025-10-26T05:45:06.802Z (3 months ago)
- Topics: go, string
- Language: Go
- Homepage:
- Size: 11.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://pkg.go.dev/github.com/lusingander/sasa)
# sasa
String utilities for Go
## Usage
### Requirements
Go 1.20+
### TrimMargin
[trimMargin](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/trim-margin.html) in Kotlin, or [stripMargin](https://www.scala-lang.org/api/current/scala/collection/StringOps.html#stripMargin:String) in Scala
```go
func main() {
s := sasa.TrimMargin(`
|foo
| bar
| baz
`)
fmt.Println(s)
// =>
//foo
// bar
// baz
t := sasa.TrimMargin(`foo
# bar
# baz`, sasa.MarginPrefix("#"))
fmt.Println(t)
// =>
//foo
// bar
// baz
}
```
### TrimIndent
[trimIndent](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/trim-indent.html) in Kotlin
```go
func main() {
s := sasa.TrimIndent(`
foo
bar
baz
`)
fmt.Println(s)
// =>
//foo
// bar
// baz
}
```
### ReplacePrefix / ReplaceSuffix
```go
func main() {
s := ReplacePrefix("aaaaabbbaaa", "aa", "x")
fmt.Println(s)
// =>
//xxabbbaaa
s := ReplaceSuffix("aaabbbaaaaa", "aa", "x")
fmt.Println(s)
// =>
//aaabbbaxx
}
```
## License
MIT