pub fn substring(str_input: &str, offset: i32, length: u32) -> StringExpand description
Extracts a substring from the given string based on the specified offset and length.
This function handles negative offsets by counting from the end of the string. It ensures that
the resulting substring contains up to length non-null characters, skipping any null characters (\x00).
If the offset is out of bounds, it returns an empty string.
§Arguments
str_input- The input string from which to extract the substring.offset- The starting position for the substring. Can be negative to indicate an offset from the end.length- The number of non-null characters to include in the substring.
§Returns
String- The extracted substring with null characters removed.
§Examples
use lowdash::substring;
let s = String::from("Hello, World!");
assert_eq!(substring(&s, 7, 5), "World");
let s = String::from("Hello, World!");
assert_eq!(substring(&s, -6, 5), "World");
let s = String::from("Hello, World!");
assert_eq!(substring(&s, 100, 5), "");
let s = String::from("Hello\x00World!");
assert_eq!(substring(&s, 0, 10), "HelloWorld");