Concat uses the strings.Builder to concatenate the input strings. - `length` is the expected length of the concatenated string. - if you are unsure about the length of the string to be concatenated, please pass 0 or a negative number. Play: https://go.dev/play/p/gD52SZHr4Kp
(length int, str ...string)
| 652 | // |
| 653 | // Play: https://go.dev/play/p/gD52SZHr4Kp |
| 654 | func Concat(length int, str ...string) string { |
| 655 | if len(str) == 0 { |
| 656 | return "" |
| 657 | } |
| 658 | |
| 659 | sb := strings.Builder{} |
| 660 | if length <= 0 { |
| 661 | sb.Grow(len(str[0]) * len(str)) |
| 662 | } else { |
| 663 | sb.Grow(length) |
| 664 | } |
| 665 | |
| 666 | for _, s := range str { |
| 667 | sb.WriteString(s) |
| 668 | } |
| 669 | return sb.String() |
| 670 | } |
| 671 | |
| 672 | // Ellipsis truncates a string to a specified length and appends an ellipsis. |
| 673 | // Play: https://go.dev/play/p/i1vbdQiQVRR |
searching dependent graphs…