pub struct StrHelper { /* private fields */ }
Expand description
Modification of &str
/ String
.
§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;
let mut helper = StrHelper::new("Hello, Rust!");
let result = helper.remove("Rust").unwrap();
assert_eq!(result, "Hello, !");
helper.push("World");
assert_eq!(helper.as_str(), "Hello, !World");
helper.move_to_the_end((7, 8));
assert_eq!(helper.as_str(), "Hello, World!");
Implementations§
Source§impl StrHelper
impl StrHelper
Sourcepub fn split_str(&self, separator: &str) -> Vec<Option<&str>>
pub fn split_str(&self, separator: &str) -> Vec<Option<&str>>
split self''' at separators and get
Vec<Option<&str>>```.
§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;
let helper = str!("hello|g|cc");
let g = helper.split_str("|").get(1).unwrap().clone();
assert_eq!(g.unwrap(), "g");
Sourcepub fn split_and_get_str(&self, separator: &str, n: usize) -> Option<&str>
pub fn split_and_get_str(&self, separator: &str, n: usize) -> Option<&str>
split self''' at separators and get
&str’‘’.
§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;
let helper = str!("hello|world|rust");
let part = helper.split_and_get_str("|", 1).unwrap();
assert_eq!(part, "world");
Sourcepub fn split_and_get_first_str(&self, separator: &str) -> Option<&str>
pub fn split_and_get_first_str(&self, separator: &str) -> Option<&str>
split self''' at separators and get first
&str’‘’.
§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;
let helper = str!("hello|world|rust");
let part = helper.split_and_get_first_str("|").unwrap();
assert_eq!(part, "hello");
Sourcepub fn split_and_get_last_str(&self, separator: &str) -> Option<&str>
pub fn split_and_get_last_str(&self, separator: &str) -> Option<&str>
split self''' at separators and get last
&str’‘’.
§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;
let helper = str!("hello|world|rust");
let part = helper.split_and_get_last_str("|").unwrap();
assert_eq!(part, "rust");
Sourcepub fn split_str_on_the_sides(&self, separator: (&str, &str)) -> Option<&str>
pub fn split_str_on_the_sides(&self, separator: (&str, &str)) -> Option<&str>
split self''' at separators on the sides and get
&str```.
§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;
let helper = str!("hello");
let l = helper.split_str_on_the_sides(("e", "lo")).unwrap();
assert_eq!(l, "l");
Source§impl StrHelper
impl StrHelper
Sourcepub fn split_string(&self, separator: &str) -> Vec<Option<String>>
pub fn split_string(&self, separator: &str) -> Vec<Option<String>>
split self''' at separators and get
Vec<Option
§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;
let helper = str!("hello|g|cc");
let g = helper.split_string("|").get(1).unwrap().clone();
assert_eq!(g.unwrap(), "g");
Sourcepub fn split_and_get_string(&self, separator: &str, n: usize) -> Option<String>
pub fn split_and_get_string(&self, separator: &str, n: usize) -> Option<String>
split self''' at separators and get
String’‘’.
§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;
let helper = str!("hello|world|rust");
let part = helper.split_and_get_string("|", 1).unwrap();
assert_eq!(part, "world");
Sourcepub fn split_and_get_first_string(&self, separator: &str) -> Option<String>
pub fn split_and_get_first_string(&self, separator: &str) -> Option<String>
split self''' at separators and get first
String’‘’.
§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;
let helper = str!("hello|world|rust");
let part = helper.split_and_get_first_string("|").unwrap();
assert_eq!(part, "hello");
Sourcepub fn split_and_get_last_string(&self, separator: &str) -> Option<String>
pub fn split_and_get_last_string(&self, separator: &str) -> Option<String>
split self''' at separators and get last
String’‘’.
§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;
let helper = str!("hello|world|rust");
let part = helper.split_and_get_last_string("|").unwrap();
assert_eq!(part, "rust");
Sourcepub fn split_string_on_the_sides(
&self,
separator: (&str, &str),
) -> Option<String>
pub fn split_string_on_the_sides( &self, separator: (&str, &str), ) -> Option<String>
split self''' at separators on the sides and get
String```.
§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;
let helper = str!("hello");
let l = helper.split_string_on_the_sides(("e", "lo")).unwrap();
assert_eq!(l, "l");
Source§impl StrHelper
impl StrHelper
Sourcepub fn split(&self, separator: &str) -> Vec<Option<StrHelper>>
pub fn split(&self, separator: &str) -> Vec<Option<StrHelper>>
split self''' at separators and get
Vec<Option
§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;
let helper = str!("hello|g|cc");
let g = helper.split("|").get(1).unwrap().clone();
assert_eq!(g.unwrap().as_str(), "g");
Sourcepub fn split_and_get(&self, separator: &str, n: usize) -> Option<StrHelper>
pub fn split_and_get(&self, separator: &str, n: usize) -> Option<StrHelper>
split self''' at separators and get
StrHelper’‘’.
§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;
let helper = str!("hello|world|rust");
let part = helper.split_and_get("|", 1).unwrap();
assert_eq!(part.as_str(), "world");
Sourcepub fn split_and_get_first(&self, separator: &str) -> Option<StrHelper>
pub fn split_and_get_first(&self, separator: &str) -> Option<StrHelper>
split self''' at separators and get first
StrHelper’‘’.
§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;
let helper = str!("hello|world|rust");
let part = helper.split_and_get_first("|").unwrap();
assert_eq!(part.as_str(), "hello");
Sourcepub fn split_and_get_last(&self, separator: &str) -> Option<StrHelper>
pub fn split_and_get_last(&self, separator: &str) -> Option<StrHelper>
split self''' at separators and get last
StrHelper’‘’.
§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;
let helper = str!("hello|world|rust");
let part = helper.split_and_get_last("|").unwrap();
assert_eq!(part.as_str(), "rust");
Sourcepub fn split_on_the_sides(&self, separator: (&str, &str)) -> Option<StrHelper>
pub fn split_on_the_sides(&self, separator: (&str, &str)) -> Option<StrHelper>
split self''' at separators on the sides and get
StrHelper```.
§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;
let helper = str!("hello");
let l = helper.split_on_the_sides(("e", "lo")).unwrap();
assert_eq!(l.as_str(), "l");
Source§impl StrHelper
impl StrHelper
Sourcepub fn split_str_at(&self, mid: usize) -> (Option<&str>, Option<&str>)
pub fn split_str_at(&self, mid: usize) -> (Option<&str>, Option<&str>)
split self''' at index and get
(Option<&str>, Option<&str>)```.
§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;
let helper = str!("Crab is Rust!");
let crab = helper.split_str_at(4).0.unwrap();
assert_eq!(crab, "Crab");
Sourcepub fn split_str_on_the_sides_at(&self, mid: (usize, usize)) -> Option<&str>
pub fn split_str_on_the_sides_at(&self, mid: (usize, usize)) -> Option<&str>
split self''' at indexes and get
&str```.
§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;
let helper = str!("Crab is Rust!");
let is = helper.split_str_on_the_sides_at((5, 7)).unwrap();
assert_eq!(is, "is");
Source§impl StrHelper
impl StrHelper
Sourcepub fn split_string_at(&self, mid: usize) -> (Option<String>, Option<String>)
pub fn split_string_at(&self, mid: usize) -> (Option<String>, Option<String>)
split self''' at index and get
(Option
§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;
let helper = str!("Crab is Rust!");
let crab = helper.split_string_at(4).0.unwrap();
assert_eq!(crab, "Crab");
Sourcepub fn split_string_on_the_sides_at(
&self,
mid: (usize, usize),
) -> Option<String>
pub fn split_string_on_the_sides_at( &self, mid: (usize, usize), ) -> Option<String>
split self''' at indexes and get
String```.
§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;
let helper = str!("Crab is Rust!");
let is = helper.split_string_on_the_sides_at((5, 7)).unwrap();
assert_eq!(is, "is");
Source§impl StrHelper
impl StrHelper
Sourcepub fn split_at(&self, mid: usize) -> (Option<StrHelper>, Option<StrHelper>)
pub fn split_at(&self, mid: usize) -> (Option<StrHelper>, Option<StrHelper>)
split self''' at index and get
(Option
§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;
let helper = str!("Crab is Rust!");
let crab = helper.split_at(4).0.unwrap();
assert_eq!(crab.as_str(), "Crab");
Sourcepub fn split_on_the_sides_at(&self, mid: (usize, usize)) -> Option<StrHelper>
pub fn split_on_the_sides_at(&self, mid: (usize, usize)) -> Option<StrHelper>
split self''' at indexes and get
StrHelper```.
§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;
let helper = str!("Crab is Rust!");
let is = helper.split_on_the_sides_at((5, 7)).unwrap();
assert_eq!(is.as_str(), "is");
Source§impl StrHelper
impl StrHelper
Sourcepub fn generate_string_from_char_vec(vector: Vec<char>) -> String
pub fn generate_string_from_char_vec(vector: Vec<char>) -> String
generate String
from Vec<char>
Sourcepub fn generate_string_from_chars(values: &[char]) -> String
pub fn generate_string_from_chars(values: &[char]) -> String
generate String
from &[char]
Source§impl StrHelper
impl StrHelper
Sourcepub fn contains(&self, pat: &str) -> bool
pub fn contains(&self, pat: &str) -> bool
get element location status in string.
§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;
let helper = str!("Hi!");
assert_eq!(helper.contains("Hi"), true);
assert_eq!(helper.contains("crab"), false);
Sourcepub fn other_as_chars(value: &str) -> Vec<char>
pub fn other_as_chars(value: &str) -> Vec<char>
get ‘’‘Vec
Source§impl StrHelper
impl StrHelper
Sourcepub fn remove(&mut self, p: &str) -> Option<String>
pub fn remove(&mut self, p: &str) -> Option<String>
remove part if it contains.
§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;
let mut helper = str!("Hello, F****** ***T *I***, World!");
let result = helper.remove("F****** ***T *I***, ").unwrap();
assert_eq!(result, helper.to_string(), "Hello, World!");
Sourcepub fn remove_at(&mut self, p_indexes: (usize, usize)) -> Option<String>
pub fn remove_at(&mut self, p_indexes: (usize, usize)) -> Option<String>
remove part at indexes.
§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;
let mut helper = str!("Hello, @@@World!");
let result = helper.remove_at((7, 10)).unwrap();
assert_eq!(result, helper.to_string(), "Hello, World!");
Source§impl StrHelper
impl StrHelper
Sourcepub fn insert(&mut self, new_part: &str, index: usize) -> Option<String>
pub fn insert(&mut self, new_part: &str, index: usize) -> Option<String>
insert element at string.
§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;
let mut helper = str!("Hello!");
let result = helper.insert(", World", 5).unwrap();
assert_eq!(result, "Hello, World!")
Sourcepub fn insert_at_the_beginning(&mut self, new_part: &str) -> Option<String>
pub fn insert_at_the_beginning(&mut self, new_part: &str) -> Option<String>
insert element at the beginning of string.
§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;
let mut helper = str!("World!");
let result = helper.insert_at_the_beginning("Hello, ").unwrap();
assert_eq!(result, "Hello, World!")
Source§impl StrHelper
impl StrHelper
Sourcepub fn move_to(
&mut self,
p_indexes: (usize, usize),
new_index: usize,
) -> Option<String>
pub fn move_to( &mut self, p_indexes: (usize, usize), new_index: usize, ) -> Option<String>
move element to index, using part’s indexes.
§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;
let mut helper = str!("He, lloWorld!");
let result = helper.move_to((4, 7), 2).unwrap();
assert_eq!(result, "Hello, World!");
Sourcepub fn move_to_the_beginning(
&mut self,
p_indexes: (usize, usize),
) -> Option<String>
pub fn move_to_the_beginning( &mut self, p_indexes: (usize, usize), ) -> Option<String>
move element to the beginning, using part’s indexes.
§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;
let mut helper = str!("World!Hello, ");
let result = helper.move_to_the_beginning((6, 13)).unwrap();
assert_eq!(result, "Hello, World!");
Sourcepub fn move_to_the_end(&mut self, p_indexes: (usize, usize)) -> Option<String>
pub fn move_to_the_end(&mut self, p_indexes: (usize, usize)) -> Option<String>
move element to the end, using part’s indexes.
§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;
let mut helper = str!("World!Hello, ");
let result = helper.move_to_the_end((0, 6)).unwrap();
assert_eq!(result, "Hello, World!");
Sourcepub fn switch_beginning_and_end(&mut self) -> Option<String>
pub fn switch_beginning_and_end(&mut self) -> Option<String>
switch first and last chars of string.
§Example:
#[macro_use] extern crate std_helper;
use std_helper::StrHelper;
let mut helper = str!("!ello, WorldH");
let _ = helper.switch_beginning_and_end();
assert_eq!(helper.as_str(), "Hello, World!")
Source§impl StrHelper
impl StrHelper
Sourcepub fn new(value: &str) -> StrHelper
pub fn new(value: &str) -> StrHelper
init struct from &str
.
§Example:
use std_helper::StrHelper;
let helper = StrHelper::new("Language Crab is Rust...");
assert_eq!(helper.as_str(), "Language Crab is Rust...");
Sourcepub fn empty() -> StrHelper
pub fn empty() -> StrHelper
init empty struct.
§Example:
use std_helper::*;
let empty_helper = StrHelper::empty();
assert_eq!(empty_helper.as_str(), "");
assert_eq!(empty_helper, str!());
Sourcepub fn from_string(value: String) -> StrHelper
pub fn from_string(value: String) -> StrHelper
init struct from String
.
§Example:
use std_helper::StrHelper;
let helper = StrHelper::from_string(String::new());
assert_eq!(helper.as_str(), "");
Sourcepub fn from_chars_vector(vector: Vec<char>) -> StrHelper
pub fn from_chars_vector(vector: Vec<char>) -> StrHelper
init struct from Vec<char>
.
§Example:
use std_helper::StrHelper;
let chars = vec!['h', 'p'];
let helper = StrHelper::from_chars_vector(chars);
assert_eq!(helper.as_str(), "hp");
Sourcepub fn from_chars(values: &[char]) -> StrHelper
pub fn from_chars(values: &[char]) -> StrHelper
init struct from &[char]
.
§Example:
use std_helper::StrHelper;
let chars = ['h', 'p'].as_ref();
let helper = StrHelper::from_chars(chars);
assert_eq!(helper.as_str(), "hp");