[#bsl-basic_string-0faf-compare-0f]
= xref:bsl.adoc[bsl]::xref:bsl/basic_string-0faf.adoc[basic&lowbar;string]::compare
:relfileprefix: ../../
:mrdocs:

Lexicographically compare this string with another sequence&period;

== Synopses

Declared in `&lt;bslstl&lowbar;string&period;h&gt;`

Lexicographically compare this string with another sequence&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
int
xref:bsl/basic_string-0faf/compare-057.adoc[compare](xref:bsl/basic_string-0faf.adoc[basic&lowbar;string] const& other) const noexcept;
----

[.small]#xref:bsl/basic_string-0faf/compare-057.adoc[_» more&period;&period;&period;_]#

Lexicographically compare this string with another sequence&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
int
xref:bsl/basic_string-0faf/compare-08.adoc[compare](CHAR&lowbar;TYPE const* other) const;
----

[.small]#xref:bsl/basic_string-0faf/compare-08.adoc[_» more&period;&period;&period;_]#

Lexicographically compare this string with another sequence&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class STRING&lowbar;VIEW&lowbar;LIKE&lowbar;TYPE&gt;
int
xref:bsl/basic_string-0faf/compare-0c.adoc[compare](STRING&lowbar;VIEW&lowbar;LIKE&lowbar;TYPE const& other) const noexcept(true);
----

[.small]#xref:bsl/basic_string-0faf/compare-0c.adoc[_» more&period;&period;&period;_]#

Lexicographically compare this string with another sequence&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
int
xref:bsl/basic_string-0faf/compare-0b.adoc[compare](
    xref:bsl/basic_string-0faf/size_type.adoc[size&lowbar;type] lhsPosition,
    xref:bsl/basic_string-0faf/size_type.adoc[size&lowbar;type] lhsNumChars,
    CHAR&lowbar;TYPE const* other) const;
----

[.small]#xref:bsl/basic_string-0faf/compare-0b.adoc[_» more&period;&period;&period;_]#

Lexicographically compare this string with another sequence&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
int
xref:bsl/basic_string-0faf/compare-050.adoc[compare](
    xref:bsl/basic_string-0faf/size_type.adoc[size&lowbar;type] position,
    xref:bsl/basic_string-0faf/size_type.adoc[size&lowbar;type] numChars,
    xref:bsl/basic_string-0faf.adoc[basic&lowbar;string] const& other) const;
----

[.small]#xref:bsl/basic_string-0faf/compare-050.adoc[_» more&period;&period;&period;_]#

Lexicographically compare this string with another sequence&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class STRING&lowbar;VIEW&lowbar;LIKE&lowbar;TYPE&gt;
int
xref:bsl/basic_string-0faf/compare-0d.adoc[compare](
    xref:bsl/basic_string-0faf/size_type.adoc[size&lowbar;type] position,
    xref:bsl/basic_string-0faf/size_type.adoc[size&lowbar;type] numChars,
    STRING&lowbar;VIEW&lowbar;LIKE&lowbar;TYPE const& other) const;
----

[.small]#xref:bsl/basic_string-0faf/compare-0d.adoc[_» more&period;&period;&period;_]#

Lexicographically compare this string with another sequence&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
int
xref:bsl/basic_string-0faf/compare-07.adoc[compare](
    xref:bsl/basic_string-0faf/size_type.adoc[size&lowbar;type] lhsPosition,
    xref:bsl/basic_string-0faf/size_type.adoc[size&lowbar;type] lhsNumChars,
    CHAR&lowbar;TYPE const* other,
    xref:bsl/basic_string-0faf/size_type.adoc[size&lowbar;type] otherNumChars) const;
----

[.small]#xref:bsl/basic_string-0faf/compare-07.adoc[_» more&period;&period;&period;_]#

Lexicographically compare this string with another sequence&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
int
xref:bsl/basic_string-0faf/compare-06.adoc[compare](
    xref:bsl/basic_string-0faf/size_type.adoc[size&lowbar;type] lhsPosition,
    xref:bsl/basic_string-0faf/size_type.adoc[size&lowbar;type] lhsNumChars,
    xref:bsl/basic_string-0faf.adoc[basic&lowbar;string] const& other,
    xref:bsl/basic_string-0faf/size_type.adoc[size&lowbar;type] otherPosition,
    xref:bsl/basic_string-0faf/size_type.adoc[size&lowbar;type] otherNumChars = npos) const;
----

[.small]#xref:bsl/basic_string-0faf/compare-06.adoc[_» more&period;&period;&period;_]#

Lexicographically compare this string with another sequence&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class STRING&lowbar;VIEW&lowbar;LIKE&lowbar;TYPE&gt;
int
xref:bsl/basic_string-0faf/compare-053.adoc[compare](
    xref:bsl/basic_string-0faf/size_type.adoc[size&lowbar;type] lhsPosition,
    xref:bsl/basic_string-0faf/size_type.adoc[size&lowbar;type] lhsNumChars,
    STRING&lowbar;VIEW&lowbar;LIKE&lowbar;TYPE const& other,
    xref:bsl/basic_string-0faf/size_type.adoc[size&lowbar;type] otherPosition,
    xref:bsl/basic_string-0faf/size_type.adoc[size&lowbar;type] otherNumChars = npos) const;
----

[.small]#xref:bsl/basic_string-0faf/compare-053.adoc[_» more&period;&period;&period;_]#

== Return Value

negative, zero, or positive according to the lexicographic order

== Parameters

[cols="1,4"]
|===
| Name| Description
| *other*
| string or character sequence to compare or use
| *lhsPosition*
| starting index of the left&hyphen;hand substring
| *lhsNumChars*
| length of the left&hyphen;hand substring
| *position*
| starting index
| *numChars*
| number of characters
| *otherNumChars*
| length of the other substring
| *otherPosition*
| starting index in the other string
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
