Trait arr_rs::alphanumeric::operations::indexing::ArrayStringIndexing
source · pub trait ArrayStringIndexing<N: Alphanumeric>where
Self: Sized + Clone,{
// Required methods
fn str_len(&self) -> Result<Array<usize>, ArrayError>;
fn count(&self, sub: &Array<N>) -> Result<Array<usize>, ArrayError>;
fn starts_with(&self, prefix: &Array<N>) -> Result<Array<bool>, ArrayError>;
fn ends_with(&self, suffix: &Array<N>) -> Result<Array<bool>, ArrayError>;
fn find(&self, sub: &Array<N>) -> Result<Array<isize>, ArrayError>;
fn rfind(&self, sub: &Array<N>) -> Result<Array<isize>, ArrayError>;
fn index(&self, sub: &Array<N>) -> Result<Array<isize>, ArrayError>;
fn rindex(&self, sub: &Array<N>) -> Result<Array<isize>, ArrayError>;
}
Expand description
ArrayTrait - Alphanumeric Array operations
Required Methods§
sourcefn str_len(&self) -> Result<Array<usize>, ArrayError>
fn str_len(&self) -> Result<Array<usize>, ArrayError>
Return string.len() element-wise
Examples
use arr_rs::prelude::*;
let expected = Array::flat(vec![6, 9, 3]);
let arr = Array::flat(vec!["AaAaAa".to_string(), "aAaAaAacc".to_string(), "abc".to_string()]);
assert_eq!(expected, arr.str_len());
sourcefn count(&self, sub: &Array<N>) -> Result<Array<usize>, ArrayError>
fn count(&self, sub: &Array<N>) -> Result<Array<usize>, ArrayError>
Returns an array with the number of non-overlapping occurrences of substring sub
Arguments
sub
- substring to search for
Examples
use arr_rs::prelude::*;
let expected = Array::flat(vec![3, 2, 1]);
let arr = Array::flat(vec!["AaAaAa".to_string(), "aAaAaA".to_string(), "bbAabb".to_string()]);
assert_eq!(expected, arr.count(&Array::single("Aa".to_string()).unwrap()));
let expected = Array::flat(vec![1]);
let arr = Array::flat(vec!["AaAaAa".to_string()]);
assert_eq!(expected, arr.count(&Array::single("AaAa".to_string()).unwrap()));
sourcefn starts_with(&self, prefix: &Array<N>) -> Result<Array<bool>, ArrayError>
fn starts_with(&self, prefix: &Array<N>) -> Result<Array<bool>, ArrayError>
Checks if string element starts with prefix
Arguments
prefix
- substring to search for
Examples
use arr_rs::prelude::*;
let expected = Array::flat(vec![true, false, false]);
let arr = Array::flat(vec!["AaAaAa".to_string(), "aAaAaA".to_string(), "bbAabb".to_string()]);
assert_eq!(expected, arr.starts_with(&Array::single("Aa".to_string()).unwrap()));
sourcefn ends_with(&self, suffix: &Array<N>) -> Result<Array<bool>, ArrayError>
fn ends_with(&self, suffix: &Array<N>) -> Result<Array<bool>, ArrayError>
Checks if string element ends with suffix
Arguments
suffix
- substring to search for
Examples
use arr_rs::prelude::*;
let expected = Array::flat(vec![false, true, false]);
let arr = Array::flat(vec!["AaAaAa".to_string(), "aAaAaA".to_string(), "bbAabb".to_string()]);
assert_eq!(expected, arr.ends_with(&Array::single("aA".to_string()).unwrap()));
sourcefn find(&self, sub: &Array<N>) -> Result<Array<isize>, ArrayError>
fn find(&self, sub: &Array<N>) -> Result<Array<isize>, ArrayError>
For each element, return the lowest index in the string where substring sub is found
Arguments
sub
- substring to search for
Examples
use arr_rs::prelude::*;
let expected = Array::flat(vec![1, 0, -1]);
let arr = Array::flat(vec!["AaAaAa".to_string(), "aAaAaA".to_string(), "bbAabb".to_string()]);
assert_eq!(expected, arr.find(&Array::single("aA".to_string()).unwrap()));
sourcefn rfind(&self, sub: &Array<N>) -> Result<Array<isize>, ArrayError>
fn rfind(&self, sub: &Array<N>) -> Result<Array<isize>, ArrayError>
For each element, return the highest index in the string where substring sub is found
Arguments
sub
- substring to search for
Examples
use arr_rs::prelude::*;
let expected = Array::flat(vec![3, 4, -1]);
let arr = Array::flat(vec!["AaAaAa".to_string(), "aAaAaA".to_string(), "bbAabb".to_string()]);
assert_eq!(expected, arr.rfind(&Array::single("aA".to_string()).unwrap()));
sourcefn index(&self, sub: &Array<N>) -> Result<Array<isize>, ArrayError>
fn index(&self, sub: &Array<N>) -> Result<Array<isize>, ArrayError>
For each element, return the lowest index in the string where substring sub is found;
alias on find
Arguments
sub
- substring to search for
Examples
use arr_rs::prelude::*;
let expected = Array::flat(vec![1, 0, -1]);
let arr = Array::flat(vec!["AaAaAa".to_string(), "aAaAaA".to_string(), "bbAabb".to_string()]);
assert_eq!(expected, arr.index(&Array::single("aA".to_string()).unwrap()));
sourcefn rindex(&self, sub: &Array<N>) -> Result<Array<isize>, ArrayError>
fn rindex(&self, sub: &Array<N>) -> Result<Array<isize>, ArrayError>
For each element, return the highest index in the string where substring sub is found;
alias on rfind
Arguments
sub
- substring to search for
Examples
use arr_rs::prelude::*;
let expected = Array::flat(vec![3, 4, -1]);
let arr = Array::flat(vec!["AaAaAa".to_string(), "aAaAaA".to_string(), "bbAabb".to_string()]);
assert_eq!(expected, arr.rindex(&Array::single("aA".to_string()).unwrap()));