Join joins any number of elements into a single string, separating them with given sep. Empty elements are ignored. However, if the argument list is empty or all its elements are empty, Join returns an empty string.
(sep byte, elem ...string)
| 65 | // Empty elements are ignored. However, if the argument list is empty or all its elements are empty, |
| 66 | // Join returns an empty string. |
| 67 | func Join(sep byte, elem ...string) string { |
| 68 | var size int |
| 69 | for _, e := range elem { |
| 70 | size += len(e) |
| 71 | } |
| 72 | if size == 0 { |
| 73 | return "" |
| 74 | } |
| 75 | |
| 76 | buf := make([]byte, 0, size+len(elem)-1) |
| 77 | for _, e := range elem { |
| 78 | if len(e) == 0 { |
| 79 | continue |
| 80 | } |
| 81 | |
| 82 | if len(buf) > 0 { |
| 83 | buf = append(buf, sep) |
| 84 | } |
| 85 | buf = append(buf, e...) |
| 86 | } |
| 87 | |
| 88 | return string(buf) |
| 89 | } |
| 90 | |
| 91 | // NotEmpty checks if all strings are not empty in args. |
| 92 | func NotEmpty(args ...string) bool { |