String


A string of text characters. Methods and properties include:

Clone

Returns a reference to this instance of String.

 PS C:\> [string]$a = "hello" PS C:\> $a hello PS C:\> $b = $a.clone() PS C:\> $b hello PS C:\> $a hello PS C:\> $b = "world" PS C:\> $b world PS C:\> $a hello PS C:\> 

Contains

Returns a value indicating whether the specified String object occurs within this string.

 PS> [string]$a = "hello" PS> $a.contains("e") True 

EndsWith

Determines whether the end of an instance of String matches a specified string.

 PS C:\> [string]$a = "hello" PS C:\> $a.endswith("lo") True 

Equals

Determines whether two String objects have the same value.

 PS C:\> [string]$a = "hello" PS C:\> [string]$b = "world" PS C:\> $a.equals($b) False 

IndexOf

Reports the index of the first occurrence of a String or one or more characters within this string.

 PS C:\> [string]$a = "hello" PS C:\> $a.indexof("l") 2 

Insert

Inserts a specified instance of String at a specified index position in this instance.

 PS C:\> [string]$a = "hello" PS C:\> $b = $a.insert(2,"-st-") PS C:\> $b he-st-llo 

LastIndexOf

Reports the index position of the last occurrence of a specified Unicode character or String within this instance.

 PS C:\> [string]$a = "hello" PS C:\> $a.lastindexof("l") 3 

Length

Gets the number of characters in this instance.

 PS C:\> [string]$a = "Hello" PS C:\> $a.length 5 

PadRight

Left-aligns the characters in this string, padding the right with spaces or a specified Unicode character for a specified total length.

 PS C:\> [string]$a = "hello" PS C:\> "-" + $a.padright(8) + "-" -hello   - 

Remove

Deletes a specified number of characters from this instance.

 PS C:\> [string]$a = "hello" PS C:\> $a.remove(3,2) hel 

Replace

Replaces all occurrences of a specified Unicode character or String in this instance with another specified Unicode character or String.

 PS C:\> [string]$a = "hello" PS C:\> $a.replace("l","p") heppo 

Split

Returns a String array containing the substrings in this instance that are delimited by elements of a specified Char or String array.

 PS C:\> [string]$a = "one,two,three" PS C:\> $b = $a.split(",") PS C:\> $b[0] one PS C:\> $b[1] two PS C:\> $b[2] three 

StartsWith

Determines whether the beginning of an instance of String matches a specified string.

 PS C:\> [string]$a = "hello" PS C:\> $a.startswith("f") False 

Substring

Retrieves a substring from this instance.

 PS C:\> [string]$a = "hello" PS C:\> $a.substring(2,3) llo 

ToCharArray

Copies the characters in this instance to a Unicode character array.

 PS C:\> [string]$a = "hello" PS C:\> $b = $a.tochararray() PS C:\> $b[0] h PS C:\> $b[4] o 

ToLower

Returns a copy of this String converted to lowercase.

 PS C:\> [string]$a = "Hello" PS C:\> $a.tolower() hello 

ToUpper

Returns a copy of this String converted to uppercase.

 PS C:\> [string]$a = "Hello" PS C:\> $a.toupper() HELLO 

Trim

Removes all occurrences of a set of specified characters from the beginning and end of this instance.

 PS C:\> [string]$a = "  hello  " PS C:\> "-" + $a.trim() + "-" -hello- 

TrimEnd

Removes all occurrences of a set of characters specified in an array from the end of this instance.

 PS C:\> [string]$a = "  hello  " PS C:\> "-" + $a.trimend() + "-" -  hello- 

TrimStart

Removes all occurrences of a set of characters specified in an array from the beginning of this instance.

 PS C:\> [string]$a = "  hello  " PS C:\> "-" + $a.trimstart() + "-" -hello - 



Windows PowerShell. TFM
Internet Forensics
ISBN: 982131445
EAN: 2147483647
Year: 2004
Pages: 289

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net