Docsity

Strings and Characters: Understanding Strings in Java with Docsity.com, Slides of Computer Science

Partial preview of the text

Download Strings and Characters: Understanding Strings in Java with Docsity.com and more Slides Computer Science in PDF only on Docsity!

Strings and Characters

Strings^ “ A string is a series of characters treated as a

single unit.” String literals are the constants and are of the

form:

“Hello world”“This is a string literal”

CopyTo method and Length Property^ In the following

instance

represents an instance

of a string. instance.Length – We’ve seen this.instance.CopyTo(sourceIndex, destination,

destinationIndex, count)

instance.CopyTo(sourceIndex, destination,

destinationIndex, count) instance.CopyTo(int,char[],int,int)Copies the characters in the string instance starting at

the sourceindex into the character array destinationbeginning at location destinationindex. The variablecount contains the number of characters to copy.

Yet More Methods^ instance.IndexOf(string)instance.IndexOf(string,int)instance.IndexOf(string,int,int)instance.LastIndexOf(string)instance.LastIndexOf(string,int)instance.LastIndexOf(string,int,int)

More!^ instance.IndexOfAny(char[])instance.IndexOfAny(char[],int)instance.IndexOfAny(char[],int,int)instance.LastIndexOfAny(char[])instance.LastIndexOfAny(char[],int)instance.LastIndexOfAny(char[],int,int)

Extracting Substings (15.8)^ instance.Substring(int)

Extract the substring starting at int and going to the

end.

instance.Substring(int,int)

Extract the substring starting at the first index and

taking the second int number of characters.

Miscellaneous String Methods^ instance.ToUpper()instance.ToLower()instance.Replace(char,char)instance.Trim()

char Methods^ Char.IsLetter(inputCharacter)Char.IsLower(inputCharacter)Char.IsUpper(inputCharacter)Char.IsDigit(inputCharacter)Char.IsPunctuation(inputCharacter)Char.IsSymbol(inputCharacter)

Regular Expression^ The last section in Chapter 15 deals with

implementing regular expressions, to verifythat strings satisfy certain properties. Thetopic of regular expressions is beyond thescope of this course, so we will omit thissection.