[#bsl-basic_string-0f3-compare-05] = xref:bsl.adoc[bsl]::xref:bsl/basic_string-0f3.adoc[basic_string<char32_t>]::compare :relfileprefix: ../../ :mrdocs: Lexicographically compare the substring of this string of the specified `lhsNumChars` length starting at the specified `lhsPosition` (or the suffix of this string starting at `lhsPosition` if `lhsPosition + lhsNumChars > length()`) with the substring of the specified `other` of the optionally specified `otherNumChars` length starting at the specified `otherPosition` (or the suffix of `other` starting at `otherPosition` if `otherPosition + otherNumChars > other.length()`). If `numChars` is not specified, `npos` is used. Return a negative value if the indicated substring of this string is less than the indicated substring of `other`, a positive value if it is greater than the indicated substring of `other`, and 0 in case of equality. `CHAR_TRAITS::lt` is used to compare characters. See {Lexicographical Comparisons}. Throw `out_of_range` if `lhsPosition > length()` or `otherPosition > other.length()`. == Synopsis Declared in `<bslstl_string.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class STRING_VIEW_LIKE_TYPE> int compare( xref:bsl/basic_string-0f3/size_type.adoc[size_type] lhsPosition, xref:bsl/basic_string-0f3/size_type.adoc[size_type] lhsNumChars, STRING_VIEW_LIKE_TYPE const& other, xref:bsl/basic_string-0f3/size_type.adoc[size_type] otherPosition, xref:bsl/basic_string-0f3/size_type.adoc[size_type] otherNumChars = npos) const; ---- [.small]#Created with https://www.mrdocs.com[MrDocs]#