String Functions

From Progzoo

Revision as of 01:16, 23 July 2008 by Andr3w (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

The methods and properties of the String type include:

String s="Andrew was here"
ExampleValueComment
s.length()14The number of characters
s.equals("another")falseTests for equality
s.substring(2,7)"drew"Characters from position 2 to just before 7
s+" once""Andrew was here once"The strings are concatenated using +
s.toUpperCase()"ANDREW WAS HERE"Also .toLowerCase()
s.indexOf("was")6Returns -1 if the substring is not there.
s.split(" ")["Andrew","was","here"]Returns an array of String.