相关文章推荐
骑白马的毛衣  ·  uniPush.sendMessage ...·  1 年前    · 
重情义的香菇  ·  Create a single file ...·  1 年前    · 
儒雅的松鼠  ·  XCode 无法识别 iOS ...·  3 年前    · 

我们有多种方法可以做到。

  • String slice range 这个例子删除了第一个和最后一个字符,并返回字符串。使用一个字符串长度的范围,从1...string.length-1开始
  • fn main() {
        let name = "Welcome";
        let result = &name[1..name.len() - 1];
        println!("{}", result);
    
    elcom
    

    using split_at with index:

    String.split_at函数是用string.len()-1分割的。

    接下来,取第一个字符串并以index=1进行分割

    打印index=1位置的字符串

    fn main() {
        let name = "Welcome";
        let name = name.split_at(name.len() - 1);
        let name = name.0.split_at(1);
        println!("{}", name.1);