Java Reference
In-Depth Information
endsWith
String
::endsWith (match :
String
) :
Boolean
Returns
true
if the String terminates with the match String provided as an
argument. Following is an example of an assertion that looks for sentences end-
ing without a period and logs a warning if found:
var
sentence :
String
:= 'I end without a period';
assert
warning (sentence.endsWith('.'))
with log
('Sentence ends without a period', sentence);
startsWith
String
::startsWith (match :
String
) :
Boolean
Returns
true
if the String begins with the match String provided as an argu-
ment. Following is an example of an assertion that looks for sentences beginning
with whitespace and logs a warning if found:
var
sentence :
String
:= ' I start with a space.';
assert
warning (
not
sentence.startsWith(' '))
with log
('Sentence starts with a space', sentence);
trim
String
::trim () :
String
Returns a String with leading and trailing whitespace removed. Note that the
sentence
variable in the previous
startsWith()
example could be corrected
using
trim()
:
sentence.trim();
normalizeSpace
String
::normalizeSpace() :
String
Search WWH ::
Custom Search