Learn R Programming

stringi (version 0.1-25)

stri_compare: Compare Strings with or without Collation

Description

These functions may be used to determine if two strings are equal (this is performed more intelligently than you may expect at a first glance) or to check whether they appear in a specific lexicographic order.

Usage

stri_compare(e1, e2, opts_collator = list())

stri_cmp(e1, e2, opts_collator = list())

Arguments

e1
character vector
e2
character vector
opts_collator
a named list as generated with stri_opts_collator with Collator's options, or NA for dummy Unicode code point comparison

Value

  • Each function returns an integer vector with comparison results of corresponding pairs of elements from e1 and e2: -1 if e1[...] < e2[...], 0 if they are equal, and 1 if greater.

Details

stri_cmp is an alias to stri_compare. They both do the same operation.

Vectorized over e1 and e2.

For more information on ICU's Collator and how to tune it up in stringi, refer to stri_opts_collator. Please note that different locale settings may lead to different results (see the examples below).

See Also

Other locale_sensitive: stri_count_fixed; stri_detect_fixed; stri_enc_detect2; stri_locate_all_fixed, stri_locate_all_fixed,, stri_locate_first_fixed, stri_locate_first_fixed,, stri_locate_last_fixed, stri_locate_last_fixed; stri_opts_collator; stri_order, stri_sort; stri_replace_all_fixed, stri_replace_all_fixed, stri_replace_first_fixed, stri_replace_first_fixed, stri_replace_last_fixed, stri_replace_last_fixed; stri_split_fixed, stri_split_fixed; stri_trans_tolower, stri_trans_totitle, stri_trans_toupper; stringi-locale; stringi-search-fixed

Examples

Run this code
stri_cmp("hladny", "chladny", stri_opts_collator(locale="pl_PL")) # in Polish ch < h
stri_cmp("hladny", "chladny", stri_opts_collator(locale="sk_SK")) # in Slovak ch > h
stri_cmp("hladny", "HLADNY") # < or > (depends on locale)
stri_cmp("hladny", "HLADNY", stri_opts_collator(strength=2)) # ==
stri_cmp("hladn\u00FD", "hladny", stri_opts_collator(strength=1, locale="sk_SK")) # ==
stri_cmp(stri_enc_nfkd('\u0105'), '\u105') # but cf. stri_enc_nfkd('\u0105') != '\u105'

Run the code above in your browser using DataLab