public class XString extends XObject
| Modifier and Type | Field and Description |
|---|---|
static XString |
EMPTYSTRING
Empty string XString object
|
CLASS_BOOLEAN, CLASS_NODESET, CLASS_NULL, CLASS_NUMBER, CLASS_RTREEFRAG, CLASS_STRING, CLASS_UNKNOWN, m_obj| Constructor and Description |
|---|
XString(String val)
Construct a XNodeSet object.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
bool()
Cast result object to a boolean.
|
void |
callVisitors(XPathVisitor visitor)
This will traverse the hierarchy, calling the visitor for each member.
|
char |
charAt(int index)
Returns the character at the specified index.
|
boolean |
equals(Object obj2) |
boolean |
equals(String obj2)
Compares this string to the specified
String. |
boolean |
equals(XObject obj2)
Tell if two objects are functionally equal.
|
boolean |
equals(XString obj2)
Compares this string to the specified object.
|
XString |
fixWhiteSpace(boolean trimHead,
boolean trimTail,
boolean doublePunctuationSpaces)
Conditionally trim all leading and trailing whitespace in the specified String.
|
void |
getChars(int srcBegin,
int srcEnd,
char[] dst,
int dstBegin)
Copies characters from this string into the destination character array.
|
int |
getType()
Tell what kind of class this is.
|
String |
getTypeString()
Given a request type, return the equivalent string.
|
boolean |
hasString()
Tell if this object contains a java String object.
|
int |
indexOf(XString str)
Returns the index within this string of the first occurrence of the specified substring.
|
int |
length()
Returns the length of this string.
|
double |
num()
Cast result object to a number.
|
boolean |
startsWith(XString prefix)
Tests if this string starts with the specified prefix.
|
boolean |
startsWith(XString prefix,
int toffset)
Tests if this string starts with the specified prefix beginning a specified index.
|
String |
str()
Cast result object to a string.
|
XString |
substring(int beginIndex)
Returns a new string that is a substring of this string.
|
XString |
substring(int beginIndex,
int endIndex)
Returns a new string that is a substring of this string.
|
double |
toDouble()
Convert a string to a double -- Allowed input is in fixed notation ddd.fff.
|
XString |
trim()
Removes white space from both ends of this string.
|
XString |
xstr()
Cast result object to a string.
|
boolWithSideEffects, deepEquals, detach, error, error, execute, greaterThan, greaterThanOrEqual, iter, lessThan, lessThanOrEqual, mutableNodeset, nodelist, nodeset, notEquals, numWithSideEffects, object, setObject, toStringasIterator, asNode, assertion, bool, canTraverseOutsideSubtree, error, execute, execute, execute, exprGetParent, exprSetParent, getColumnNumber, getExpressionOwner, getLineNumber, getPublicId, getSystemId, isSameClass, isStableNumber, numpublic static final XString EMPTYSTRING
public XString(String val)
val - String object this will wrap.public int getType()
public String getTypeString()
getTypeString in class XObjectpublic boolean hasString()
public double num()
public double toDouble()
public boolean bool()
public XString xstr()
public String str()
public int length()
public char charAt(int index)
0 to
length() - 1. The first character of the sequence is at index 0, the next
at index 1, and so on, as for array indexing.index - the index of the character.0.IndexOutOfBoundsException - if the index argument is negative or not less
than the length of this string.public void getChars(int srcBegin,
int srcEnd,
char[] dst,
int dstBegin)
srcBegin - index of the first character in the string to copy.srcEnd - index after the last character in the string to copy.dst - the destination array.dstBegin - the start offset in the destination array.IndexOutOfBoundsException - If any of the following is true:
srcBegin is negative.
srcBegin is greater than srcEnd
srcEnd is greater than the length of this string
dstBegin is negative
dstBegin+(srcEnd-srcBegin) is larger than dst.length
NullPointerException - if dst is nullpublic boolean equals(XObject obj2)
public boolean equals(String obj2)
String. The result is true if
and only if the argument is not null and is a String object that
represents the same sequence of characters as this object.obj2 - the object to compare this String against.true if the Strings are equal; false otherwise.String.compareTo(java.lang.String),
String.equalsIgnoreCase(java.lang.String)public boolean equals(XString obj2)
true if and only if
the argument is not null and is a String object that represents the
same sequence of characters as this object.obj2 - the object to compare this String against.true if the String are equal; false otherwise.String.compareTo(java.lang.String),
String.equalsIgnoreCase(java.lang.String)public boolean startsWith(XString prefix, int toffset)
prefix - the prefix.toffset - where to begin looking in the string.true if the character sequence represented by the argument is a prefix of
the substring of this object starting at index toffset; false
otherwise. The result is false if toffset is negative or
greater than the length of this String object; otherwise the result is the
same as the result of the expression
this.subString(toffset).startsWith(prefix)
NullPointerException - if prefix is null.public boolean startsWith(XString prefix)
prefix - the prefix.true if the character sequence represented by the argument is a prefix of
the character sequence represented by this string; false otherwise. Note also
that true will be returned if the argument is an empty string or is equal to
this String object as determined by the equals(Object) method.NullPointerException - if prefix is null.public int indexOf(XString str)
isthis.startsWith(str, k)
true.str - any string.-1 is returned.NullPointerException - if str is null.public XString substring(int beginIndex)
Examples:
"unhappy".substring(2) returns "happy" "Harbison".substring(3) returns "bison" "emptiness".substring(9) returns "" (an empty string)
beginIndex - the beginning index, inclusive.IndexOutOfBoundsException - if beginIndex is negative or larger than the
length of this String object.public XString substring(int beginIndex, int endIndex)
beginIndex and extends to the character at index endIndex - 1
. Thus the length of the substring is endIndex-beginIndex.beginIndex - the beginning index, inclusive.endIndex - the ending index, exclusive.IndexOutOfBoundsException - if the beginIndex is negative, or
endIndex is larger than the length of this String object, or
beginIndex is larger than endIndex.public XString trim()
public XString fixWhiteSpace(boolean trimHead, boolean trimTail, boolean doublePunctuationSpaces)
trimHead - Trim leading whitespace?trimTail - Trim trailing whitespace?doublePunctuationSpaces - Use double spaces for punctuation?public void callVisitors(XPathVisitor visitor)
callVisitors in interface XPathVisitablecallVisitors in class XObjectvisitor - The visitor whose appropriate method will be called.Copyright © 2022–2025 HtmlUnit. All rights reserved.