Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR RUST

rust string slice

//	creates a variable named str and assigns it a string value of "Hello, world!" .
let str = "Hello, world!";

//	creates a variable named str_slice and assigns it a reference to the first two characters of str .
let str_slice = &str[0..1];

//	creates a variable named str_slice and assigns it a reference to the entire string.
let str_slice = &str[..];

//	creates a variable named str_slice and assigns it a reference to the fourth character onwards.
let str_slice = &str[3..];
 
PREVIOUS NEXT
Tagged: #rust #string #slice
ADD COMMENT
Topic
Name
4+1 =