rust split 字符串分割

180it 2023-03-06 AM 568℃ 0条

rust:字符串分割

fn main() {

    let location = String::from("/sso.iam.local/auth/admin/realms/xxx/groups/c1bf8486-4c7c-4669-9939-ab765e5699e1");
    let pos :Vec<&str> = location.split("/").collect();    
    println!("id: {}",pos[pos.len()-1]);
}



fn main() {

    let location = String::from("/sso.iam.local/auth/admin/realms/xxx/groups/c1bf8486-4c7c-4669-9939-ab765e5699e1");
    let pos = location.rfind("/").unwrap();
    let (_, lst) = location.split_at(pos + 1);
    println!("id:{}",lst);
}

支付宝打赏支付宝打赏 微信打赏微信打赏

如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!

标签: none

rust split 字符串分割