Thanks for your reply. the `str[0:len(str)-1]` not work for NO ascii 
chracters.

https://play.golang.org/p/7i6-3Zcy36



On Friday, May 26, 2017 at 11:06:10 PM UTC+8, messju mohr wrote:
>
> Hi, 
>
> On Fri, May 26, 2017 at 07:10:43AM -0700, long...@gmail.com <javascript:> 
> wrote: 
> >                var str = "a/b/c/d/c" 
> >                // I want remove last chracter from str 
> >                var strRunes = []rune(str) 
> >                var newStrRunes = strRunes[0 : len(strRunes)-1] 
> >                // then I want get last index of chracters `/c`, I need 
> convert to string back!??? 
> >                strings.LastIndex(string(newStrRunes), "/c") 
> >                // Does there have a method that LastIndex(rs []rune, s 
> string) 
> >    Thanks for your help! 
>
> You don't have to convert to a slice of runes: 
>
>         var str = "a/b/c/d/c" 
>         var newStr = str[0:len(str)-1] 
>         fmt.Println(strings.LastIndex(newStr, "/c")) 
>
> Or you have to convert your slice back to a string: 
>
>         var str = "a/b/c/d/c" 
>         var strRunes = []rune(str) 
>         var newStrRunes = strRunes[0 : len(strRunes)-1] 
>         fmt.Println(strings.LastIndex(string(newStrRunes), "/c")) 
>
> HTH 
> messju 
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to