Add replace function for characters
This commit is contained in:
parent
ec67879759
commit
d6fd5416b0
@ -1328,7 +1328,7 @@ The following standard methods (defined in the [`MoreStringPackage`](#packages)
|
|||||||
| `index_of` | character/sub-string to search for, start index _(optional)_ | returns the index that a certain character or sub-string occurs in the string, or -1 if not found |
|
| `index_of` | character/sub-string to search for, start index _(optional)_ | returns the index that a certain character or sub-string occurs in the string, or -1 if not found |
|
||||||
| `sub_string` | start index, length _(optional)_ | extracts a sub-string (to the end of the string if length is not specified) |
|
| `sub_string` | start index, length _(optional)_ | extracts a sub-string (to the end of the string if length is not specified) |
|
||||||
| `crop` | start index, length _(optional)_ | retains only a portion of the string (to the end of the string if length is not specified) |
|
| `crop` | start index, length _(optional)_ | retains only a portion of the string (to the end of the string if length is not specified) |
|
||||||
| `replace` | target sub-string, replacement string | replaces a sub-string with another |
|
| `replace` | target character/sub-string, replacement character/string | replaces a sub-string with another |
|
||||||
| `trim` | _none_ | trims the string of whitespace at the beginning and end |
|
| `trim` | _none_ | trims the string of whitespace at the beginning and end |
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
@ -226,6 +226,36 @@ def_package!(crate:MoreStringPackage:"Additional string utilities, including str
|
|||||||
},
|
},
|
||||||
map,
|
map,
|
||||||
);
|
);
|
||||||
|
reg_trinary_mut(
|
||||||
|
lib,
|
||||||
|
"replace",
|
||||||
|
|s: &mut String, find: String, sub: char| {
|
||||||
|
let new_str = s.replace(&find, &sub.to_string());
|
||||||
|
s.clear();
|
||||||
|
s.push_str(&new_str);
|
||||||
|
},
|
||||||
|
map,
|
||||||
|
);
|
||||||
|
reg_trinary_mut(
|
||||||
|
lib,
|
||||||
|
"replace",
|
||||||
|
|s: &mut String, find: char, sub: String| {
|
||||||
|
let new_str = s.replace(&find.to_string(), &sub);
|
||||||
|
s.clear();
|
||||||
|
s.push_str(&new_str);
|
||||||
|
},
|
||||||
|
map,
|
||||||
|
);
|
||||||
|
reg_trinary_mut(
|
||||||
|
lib,
|
||||||
|
"replace",
|
||||||
|
|s: &mut String, find: char, sub: char| {
|
||||||
|
let new_str = s.replace(&find.to_string(), &sub.to_string());
|
||||||
|
s.clear();
|
||||||
|
s.push_str(&new_str);
|
||||||
|
},
|
||||||
|
map,
|
||||||
|
);
|
||||||
reg_unary_mut(
|
reg_unary_mut(
|
||||||
lib,
|
lib,
|
||||||
"trim",
|
"trim",
|
||||||
|
Loading…
Reference in New Issue
Block a user