[#bsl-basic_string-0faf-compare-0d] = xref:bsl.adoc[bsl]::xref:bsl/basic_string-0faf.adoc[basic_string]::compare :relfileprefix: ../../ :mrdocs: Lexicographically compare the substring of this string of the specified `numChars` length starting at the specified `position` (or the suffix of this string starting at `position` if `position + numChars > length()`) with the specified `other`, and return a negative value if the indicated substring of this string is less than `other`, a positive value if it is greater than `other`, and 0 in case of equality. `CHAR_TRAITS::lt` is used to compare characters. See {Lexicographical Comparisons}. Throw `out_of_range` if `position > 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-0faf/size_type.adoc[size_type] position, xref:bsl/basic_string-0faf/size_type.adoc[size_type] numChars, STRING_VIEW_LIKE_TYPE const& other) const; ---- [.small]#Created with https://www.mrdocs.com[MrDocs]#