Advertisement
Guest User

Untitled

a guest
Jul 19th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.61 KB | None | 0 0
  1. fn main(){
  2.     let s = "This is a string";
  3.     let subst1 = s[10..16].to_string().clone();
  4.     let subst2 = s[10..].to_string().clone();
  5.     println!("{}", subst1 == subst2);
  6.     let doublesub = subst1 + &subst2;
  7.     println!("{}", doublesub);
  8.     // Using split iterator to print word by word
  9.     for tempstr in s.split(' ') {
  10.         println!("{}", tempstr);
  11.     }
  12.     // Another useful function of the split iterator
  13.     // collect() Creates a vector ~["This", "is", "a", "string"]
  14.     let wordvec: Vec<&str> = s.split(' ').collect();
  15.     for &s in wordvec.iter() {
  16.         println!("{}", s);
  17.     }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement