String Operators

Parent Previous Next

VisualSim                                                                                                                                    

String Operators


Function & Argument Type(s)

Description

Examples

 int

codePointAt(int index)
          Returns the character (Unicode code point) at the specified index.

>> a = "abcedefghi"
"abcedefghi"
>> b = a.codePointAt(2)
99

 int

codePointBefore(int index)
          Returns the character (Unicode code point) before the specified index.

>> a = "abcedefghi"
"abcedefghi"
>> b = a.codePointBefore(2)
98

 int

codePointCount(int beginIndex, int endIndex)
          Returns the number of Unicode code points in the specified text range of this String.

>> a = "abcedefghi"
"abcedefghi"
>> b = a.codePointCount(2,4)
2

 int

compareToIgnoreCase(String str)
          Compares two strings lexicographically, ignoring case differences.

>> a = "abcedefghi"
"abcedefghi"
>> c = "asdf"
"asdf"
>> b = a.compareToIgnoreCase(c)
-17

 String

concat(String str)
          Concatenates the specified string to the end of this string.

>> a = "abcedefghi"
"abcedefghi"
>> c = "xtz"
"xtz"
>> b = a.concat(c)
"abcedefghixtz"

 boolean

contains(CharSequence s)
          Returns true if and only if this string contains the specified sequence of char values.

>> a = "abcedefghi"
"abcedefghi"
>> b = a.contains(a)
true

 boolean

contentEquals(CharSequence cs)
          Compares this string to the specified CharSequence.

>> a = "abcdefghi"
"abcdefghi"
>> b = a.contentEquals(a)
true

 boolean

contentEquals(StringBuffer sb)
          Compares this string to the specified StringBuffer.

>> a = "abcdefghi"
"abcdefghi"
>> b = a.contentEquals(a)
true

 boolean

endsWith(String suffix)
          Tests if this string ends with the specified suffix.

>> a = "abcdgefhi"
"abcdgefhi"
>> b = a.endsWith("c")
false

 boolean

equalsIgnoreCase(String anotherString)
          Compares this String to another String, ignoring case considerations.

>> a = "abcdgefhi"
"abcdgefhi"
>> b = a.equalsIgnoreCase("b")
false

 int

hashCode()
          Returns a hash code for this string.

>> a = "abcdgefhi"
"abcdgefhi"
>> b = a.hashCode()
396996423

 int

indexOf(String str)
          Returns the index within this string of the first occurrence of the specified substring.

>> a = "abcdgefhi"
"abcdgefhi"
>> c = a.indexOf("c")
2

 int

indexOf(String str, int fromIndex)
          Returns the index within this string of the first occurrence of the specified substring, starting at the specified index.

>> a = "abcdgefhi"
"abcdgefhi"
>> c = a.indexOf("c",2)
2

 String

intern()
          Returns a canonical representation for the string object.

>> a = "abcdgefhi"
"abcdgefhi"
>> d = a.intern()
"abcdgefhi"

 boolean

isEmpty()
          Returns true if, and only if, length() is 0.

>> a = "abcdefghi"
"abcdefghi"
>> b = a.isEmpty()
false

 int

lastIndexOf(String str)
          Returns the index within this string of the rightmost occurrence of the specified substring.

>> a = "abcdefghi"
"abcdefghi"
>> c = a.lastIndexOf("b")
1

 int

lastIndexOf(String str, int fromIndex)
          Returns the index within this string of the last occurrence of the specified substring, searching backward starting at the specified index.

>> a = "abcdefghi"
"abcdefghi"
>> c = a.lastIndexOf("b",2)
1

 int

length()
          Returns the length of this string.

>> a = "abcdefghi"
"abcdefghi"
>> c = a.length()
9

 boolean

matches(String regex)
          Tells whether or not this string matches the given string.

>> a = "abcdefghi"
"abcdefghi"
>> d=a.matches("a")
false

 int

offsetByCodePoints(int index, int codePointOffset)
          Returns the index within this String that is offset from the given index by codePointOffset code points.

>> a = "abcdefghi"
"abcdefghi"
>> e = a.offsetByCodePoints(1,1)
2

 boolean

regionMatches(boolean ignoreCase, int toffset, String other, int ooffset, int len)
          Tests if two string regions are equal.

>> a = "abcdefghi"
"abcdefghi"
>> f = a.regionMatches(true,0,"abc",1,2)
false

 boolean

regionMatches(int toffset, String other, int ooffset, int len)
          Tests if two string regions are equal.

>> a = "abcdefghi"
"abcdefghi"
>> f = a.regionMatches(0,"abc",1,2)
false

 String

replaceAll(String regex, String replacement)
          Replaces each substring of this string that matches the given regular expression with the given replacement.

>> a = "abcdefghi"
"abcdefghi"
>> f = a.replaceAll("a+b","c")
"ccdefghi"

 String

replaceFirst(String regex, String replacement)
          Replaces the first substring of this string that matches the given regular expression with the given replacement.

>> a = "abcdefghi"
"abcdefghi"
>> f = a.replaceFirst("a+b","c")
"ccdefghi"

 String[]

split(String regex)
          Splits this string around matches of the given regular expression.

>> a = "abcdefghi"
"abcdefghi"
>> f = a.split("a+b")
{"", "cdefghi"}

 String[]

split(String regex, int limit)
          Splits this string around matches of the given regular expression.

>> a = "abcdefghi"
"abcdefghi"
>> f = a.split("a+b",4)
{"", "cdefghi"}

 boolean

startsWith(String prefix)
          Tests if this string starts with the specified prefix.

>> a = "abcdefghi"
"abcdefghi"
>> g = a.startsWith("a")
true

 boolean

startsWith(String prefix, int toffset)
          Tests if the substring of this string beginning at the specified index starts with the specified prefix.

>> a = "abcdefghi"
"abcdefghi"
>> g = a.startsWith("a",2)
false

 String

substring(int beginIndex)
          Returns a new string that is a substring of this string.

>> a = "abcdefghi"
"abcdefghi"
>> g = a.substring(2)
"cdefghi"

 String

substring(int beginIndex, int endIndex)
          Returns a new string that is a substring of this string.

>> a = "abcdefghi"
"abcdefghi"
>> g = a.substring(2,4)
"cd"

 String

toLowerCase()
          Converts all of the characters in this String to lower case using the rules of the default locale.

>> a = "abcdefghi"
"abcdefghi"
>> g = a.toLowerCase()
"abcdefghi"

 String

toString()
          This object (which is already a string!) is itself returned.

>> a = "abcdefghi"
"abcdefghi"
>> g = a.toString()
""abcdefghi""

 String

toUpperCase()
          Converts all of the characters in this String to upper case using the rules of the default locale.

>> a = "abcdefghi"
"abcdefghi"

 String

trim()
          Returns a copy of the string, with leading and trailing whitespace omitted.

>> a = "    abcdefghi    "
"    abcdefghi    "
>> g = a.trim()
"abcdefghi"

 

 

 

Created with the Personal Edition of HelpNDoc: Produce Kindle eBooks easily