Added Join and improved test
This commit is contained in:
parent
9620206ee8
commit
af92f694d9
16
py/str.go
16
py/str.go
@ -1,6 +1,10 @@
|
||||
package py
|
||||
|
||||
import ("fmt")
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
|
||||
func Chr(x rune) string {
|
||||
@ -14,3 +18,13 @@ func Ord(x string) rune {
|
||||
}
|
||||
return rune(x[0])
|
||||
}
|
||||
|
||||
|
||||
func Join(sep string, iter interface{}) string {
|
||||
var list []string
|
||||
viter := reflect.ValueOf(iter)
|
||||
for i := 0; i < viter.Len(); i++ {
|
||||
list = append(list, fmt.Sprintf("%v", viter.Index(i).Interface()))
|
||||
}
|
||||
return strings.Join(list, sep)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user