Package: Collections-Strings
Class: String
Introduction
Environment: container
Super class: Array
A String is an indexed collection of Characters.
A String is a sequence of characters. It is a subclass of Array, and therefore inherits all the Array operations.
You can compare strings using the operator =
, >=,
>', <
, <=
. For example:
You can also concatenate strings using the ,
operator. For example:
Actually you can concatenate any two objects to a string. For example:
To concatenate strings with new line, you can use String crlf
or String lf
. For example:
Class Method
Category: instance creation
cr
- Answer a string containing a single carriage return character.crlf
- Answer a string containing a carriage return and a linefeed.lf
- Answer a string containing a linefeed character.tab
- Answer a string containing a single tab character.
Instance Method
Category: accessing
replaceAll:with:
- replace all occurrences of a substring with another stringFor example:
Category: combining
+
- Concatenate two strings.
Category: comparing
<
- answer whether the receiver sorts before aString. The collation order is simple ascii (with case differences)It compares two strings lexicographically, which means that it compares the strings character by character, according to the Unicode value of each character. If the first string is lexicographically less than the second string, the method answers true, otherwise it answers false.
For example:
<=
- answer whether the receiver sorts before or equal to aString. The collation order is simple ascii (with case differences).It compares two strings lexicographically, which means that it compares the strings character by character, according to the Unicode value of each character. If the first string is lexicographically less than or equal with the second string, the method answers true, otherwise it answers false.
For example:
=
- answer whether the receiver sorts equally as aString. The collation order is simple ascii (with case differences).For exmaple:
>
- answer whether the receiver sorts after aString. The collation order is simple ascii (with case differences).It compares two strings lexicographically, which means that it compares the strings character by character, according to the Unicode value of each character. If the first string is lexicographically greater than the second string, the method answers true, otherwise it answers false.
For example:
>=
- answer whether the receiver sorts after or equal to aString. The collation order is simple ascii (with case differences).It compares two strings lexicographically, which means that it compares the strings character by character, according to the Unicode value of each character. If the first string is lexicographically greater than or equal with the second string, the method answers true, otherwise it answers false.
For example:
isLowercase
- Test if the receiver is lower case.For example:
isUppercase
- Test if the receiver is upper case.For example:
Category: convenience
langCode
- answer the language code of the string.For example:
Category: converting
asInteger
- return the integer present in the receiver, or nil. In case of float, returns the integer part.For example:
If the string contains an illegal character, an exception will be triggered.
We also support to parse a string including a comma to separate groups of thousands, for example:
asIntegerIgnoreJunk
- return the integer present in the receiver, or nil. In case of float, returns the integer part.The junk in string will be ignored. If no integer is identified, it returns nil. For example:
asLowercase
- answer a String made up from the receiver whose characters are all lowercase.For example:
asNumber
- return the number present in the receiver, or raise an exception if there are illegal characters inside the string.For example:
asNumberIgnoreJunk
- return the number present in the receiver by removing junk in string. If no number is identified, it returns nil.For example:
asString
- return a copy of the original string in the receiverasURLPath
- Convert the given text into a URL-encoded string suitable for inclusion in a URL path.For example:
asUppercase
- answer a String made up from the receiver whose characters are all uppercase.For example:
splitOn:
- split the string by specified separator and answer an array for splitted items.For example:
Category: copying
copyFrom:to:
- answer a copied subrange of the receiver..For example:
left:
- answer a copied subrange of the receiver from left with specified size.For example:
right:
- answer a copied subrange of the receiver from right with specified size.For example:
trimLeft
- Trim whitespaces from the left side of the receiving string.For example:
trimRight
- Trim whitespaces from the right side of the receiving string.For example:
Category: date-time
dateAdd:as:format:
- adds time/date interval to a date and then returns the dateThe following category can be used in second argument for
as:
#year
the difference in years#month
the difference in months#day
the difference in days.#hour
the difference in hours.#minute
the difference in minutes.#second
the difference in seconds.
For example:
dateDiff:as:
- find the difference between two dates string.The following category can be used in second argument for
as:
#year
the difference in years#month
the difference in months#day
the difference in days.#hour
the difference in hours.#minute
the difference in minutes.#second
the difference in seconds.
For example:
dateFormat:
- Format the date time string with the given format. The valid format control strings are:YYYY
Four-digit yearMM
Two-digit month (01=January, etc.)M
One or two-digit monthDD
Two-digit day of month (01 through 31)D
One or two-digit day of monthhh
Two digits of hour (00 through 23) (am/pm NOT allowed)h
One or two digits of hour (0 through 23) (am/pm NOT allowed)mm
Two digits of minute (00 through 59)m
One or two digits of minute (0 through 59)ss
Two digits of second (00 through 59)s
One or two digits of second (0 through 59)
For example:
And to get the previous year.
Category: finding/searching
findString:
- answer the index of the first substring within the receiver.If the receiver does not contain substring, answer 0.
For example:
findString:startingAt:
- answers the index of the first substring within the receiver from the start. If the receiver does not contain a substring, the answer is 0.For example:
Category: instance creation
new
- Create a new string object by copy current string.
Category: testing
isSequenceable
- Answer whether the receiver can be accessed by a numeric index with #at:/#at:put:.
Last updated