O'Reilly logo

Learning C# 2005, 2nd Edition by Brian MacDonald, Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Manipulating Strings

The String class provides a host of methods for comparing , searching, and manipulating strings , the most important of which are shown in Table 15-1.

Table 15-1. String class properties and methods

Method or property

Explanation

Chars

Property that returns the string indexer

Compare( )

Overloaded public static method that compares two strings

Copy( )

Public static method that creates a new string by copying another

Equals( )

Overloaded public static and instance method that determines if two strings have the same value

Format( )

Overloaded public static method that formats a string using a format specification

Length

Property that returns the number of characters in the instance

PadLeft( )

Right-aligns the characters in the string, padding to the left with spaces or a specified character

PadRight( )

Left-aligns the characters in the string, padding to the right with spaces or a specified character

Remove( )

Deletes the specified number of characters

Split( )

Divides a string, returning the substrings delimited by the specified characters

StartsWith( )

Indicates if the string starts with the specified characters

Substring( )

Retrieves a substring

ToCharArray( )

Copies the characters from the string to a character array

ToLower( )

Returns a copy of the string in lowercase

ToUpper( )

Returns a copy of the string in uppercase

Trim( )

Removes all occurrences of a set of specified characters from beginning and end of the string

TrimEnd( )

Behaves like Trim( )

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required