Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Please answer these questions before submitting your issue. Thanks!
go version
go1.6 darwin/amd64
go env
darwin/amd64
package main
import ( "fmt" "path/filepath" "strings" )
func main() { path := "Order.thrift"
b := filepath.Base(path) fmt.Println(b) // Order.thrift e := filepath.Ext(path) fmt.Println(e) // .thrift n := strings.TrimRight(b, e) fmt.Println(n)
}
Order
Orde
The text was updated successfully, but these errors were encountered:
Trimright removes characters in the set e from b, starting from the right. It's not what you want.
You want, n := b[:len(b)-len(e)]
As you know that e is the suffix of b
On 5 Mar 2016, at 20:15, Hongjian Zhu notifications@github.com wrote: Please answer these questions before submitting your issue. Thanks! What version of Go are you using (go version)? go1.6 darwin/amd64 What operating system and processor architecture are you using (go env)? darwin/amd64 What did you do? (Use play.golang.org to provide a runnable example, if possible.) package main import ( "fmt" "path/filepath" "strings" ) func main() { path := "Order.thrift" b := filepath.Base(path) fmt.Println(b) // Order.thrift e := filepath.Ext(path) fmt.Println(e) // .thrift n := strings.TrimRight(b, e) fmt.Println(n) } What did you expect to see? Order What did you see instead? Orde — Reply to this email directly or view it on GitHub.
On 5 Mar 2016, at 20:15, Hongjian Zhu notifications@github.com wrote:
What version of Go are you using (go version)? go1.6 darwin/amd64
What operating system and processor architecture are you using (go env)? darwin/amd64
What did you do? (Use play.golang.org to provide a runnable example, if possible.) package main
b := filepath.Base(path) fmt.Println(b) // Order.thrift
e := filepath.Ext(path) fmt.Println(e) // .thrift
n := strings.TrimRight(b, e) fmt.Println(n) }
What did you expect to see? Order
What did you see instead? Orde
— Reply to this email directly or view it on GitHub.
Sorry, something went wrong.
@davecheney, @minux thank you guys for your kindly replay :-]
No branches or pull requests
Please answer these questions before submitting your issue. Thanks!
go version
)?go1.6 darwin/amd64
go env
)?darwin/amd64
(Use play.golang.org to provide a runnable example, if possible.)
package main
import (
"fmt"
"path/filepath"
"strings"
)
func main() {
path := "Order.thrift"
}
Order
Orde
The text was updated successfully, but these errors were encountered: