The strip_prefix()
method is used to strip or remove a starting string or prefix of a string. It returns the slice with the specified prefix removed from the original string. This method returns the sub-string after the prefix that is wrapped by Some
. If the specified prefix does not start the string then it is a None
.
string.split_prefix(prefix)
string
: This is the string that we want to remove a prefix of.
prefix
: This is the prefix of the string
that we want to slice away.
fn main() {// create some stringslet str1 = "Edpresso";let str2 = "Educative";let str3 = "Rust";let str4 = "Educative is the best platform!";// strip some prefixesprintln!("Stripping {:?} from {} = {:?}","Ed",str1, str1.strip_prefix("Ed"));println!("Stripping {:?} from {} = {:?}","cative",str2, str2.strip_prefix("cative"));println!("Stripping {:?} from {} = {:?}","R",str3, str3.strip_prefix("R"));println!("Stripping {:?} from {} = {:?}","Educative is",str4, str4.strip_prefix("Educative is"));}
strip_prefix()
method. Then we print the results to the console.