compareTo.String: Compares this string to another Object

Description Usage Arguments Value Author(s) See Also Examples

Description

Compares this string to another Object (or character string) lexically.

Usage

1
2
## S3 method for class 'String'
compareTo(this, obj, ...)

Arguments

index

the index of the character.

Value

Returns -1 if this String is lexicographically less than the other string, +1 if this String is lexicographically greater than the other string, and 0 if they are lexicographically equal.

Author(s)

Henrik Bengtsson (http://www.braju.com/R/)

See Also

*equals(), *equalsIgnoreCase(), *compareTo(), *regionMatches()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
  s1 <- String("abc")
  s2 <- String("ABC")
  s3 <- String("def")
  s4 <- String(" def")

  compareTo(s1, s1)         #  0
  compareTo(s1, s2)         # +1
  compareTo(s2, s1)         # -1
  compareTo(s1, s3)         # -1
  compareTo(s3, s4)         # +1
  compareTo("def", " def")  # +1

HenrikBengtsson/R.lang documentation built on May 8, 2019, 7:50 p.m.