public final class NSString extends NSObject
Represents a string.
String
Constructor and Description |
---|
NSString(java.lang.String theString)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getValue()
Get the unmodifiable value of this object.
|
boolean |
isTrue()
Return whether or not the value evaluates to true.
|
byte[] |
toBytes()
Get the raw data of the value.
|
double |
toDouble()
Return the value as a double.
|
long |
toLong()
Return the value as a long.
|
java.lang.Number |
toNumber()
Return the value as a number.
|
public NSString(java.lang.String theString)
theString
- value of the new objectpublic java.lang.String getValue()
getValue
in class NSObject
NSObject.toString()
public boolean isTrue()
Return whether or not the value evaluates to true.
A value returns to true if and only if
NSBoolean
type NSBoolean.TRUE
NSString
which has a length greater than zero and does not equal "NO" or "False" (case insensitive)NSNumber
greater than 0NSCollection
which contains more than zero elementsNSDate
NSData
with a length greater than 0public byte[] toBytes()
public java.lang.Number toNumber()
Return the value as a number.
If this is not a NSNumber
the number is derived from the value.
The number is derived in the following way
NSNumber
: the actual number valueNSCollection
: the amount of childrenNSData
: the length in bytesNSBoolean
: always byte; 0 for false, 1 for trueNSString
: If the String is numeric, return the number in the string. Otherwise return 0*If you need to be sure about the result (e.g. you need to know if the result is user intended or a guess) you should do instanceof checks yourself.
*This behaviour is exactly as the library works and even though one could argue that the method should return null instead of 0, the method returns 0 and will never return null. There are a couple reasons for this:
NSObject.toLong()
and NSObject.toDouble()
use NSObject.toNumber()
;NullPointerException
s.NSObject.toNumber()
on any NSObject
is dirty anyway.NSObject
is an NSNumber
.public long toLong()
NSInteger
the long value is derived from the actual value.