Function lib_rapid::compsci::stringhelpers::strcmp
source · pub const fn strcmp(s1: &str, s2: &str) -> i16
Expand description
A Rust implementation of C’s strcmp()
function.
Arguments
s1
- The String reference to be compared to.s2
- The String which is compared withs1
.
Returns
It returns:
0
, ifs1 == s2
.s2[i] - s1[i]
, ifs1[i] < s2[i]
in ASCII.s1[i] - s2[i]
, ifs1[i] > s2[i]
in ASCII.
Examples
use lib_rapid::compsci::stringhelpers::strcmp;
let a = "hello";
let b = "hEllo";
assert!(strcmp(a, b) == 101 - 69);
// 101 == 'e' in ASCII.
// 69 == `E` in ASCII.
use lib_rapid::compsci::stringhelpers::strcmp;
let a = "hello";
let b = "hello";
assert!(strcmp(a, b) == 0);
use lib_rapid::compsci::stringhelpers::strcmp;
let a = "Hello";
let b = "hello";
assert!(strcmp(a, b) == 72 - 104);
// 72 == 'H' in ASCII.
// 104 == `h` in ASCII.