THE BEST NEWSLETTER ANYWHERE
Join 6,000 subscribers and get a daily digest of full stack tutorials delivered to your inbox directly.No spam ever. Unsubscribe any time.
This tutorial explains multiple ways to remove the first and last characters of a string in Rust.
There are multiple ways we can do it.
fn main() {
let name = "Welcome";
let result = &name[1..name.len() - 1];
println!("{}", result);
}
Output:
elcom
using split_at with index:
String.split_at functions is split with string.len()-1
Next, takes the first string and split it with index=1
Print the string with index=1 position
fn main() {
let name = "Welcome";
let name = name.split_at(name.len() - 1);
let name = name.0.split_at(1);
println!("{}", name.1);
}
Output:
elcom
🧮 Tags
Recent posts
Nodejs package.json resolutions How to find Operating System username in NodeJS? How to convert Double to Integer or Integer to double in Dart| Flutter By Example Ways to skip test case execution in Gradle project build Learn Gradle | tutorials, and examplesRelated posts