Export (0) Print
Expand All

String.Trim Method (Char[])

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

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

public string Trim (
	params char[] trimChars
)
public String Trim (
	char[] trimChars
)
public function Trim (
	... trimChars : char[]
) : String

Parameters

trimChars

An array of Unicode characters to be removed or a null reference (Nothing in Visual Basic).

Return Value

The String that remains after all occurrences of the characters in trimChars are removed from the beginning and end of this instance. If trimChars is a null reference (Nothing in Visual Basic), white space characters are removed instead.

For more information about what Unicode characters are categorized as white space characters, see the Remarks section of the Trim method overload.

The following code example demonstrates the Trim(Char[]) method overload.

using System;

class stringTrim2 {
    public static void Main() {
        String str1 = "*;|@123***456@|;*";
	String delim = "*;|@";
	String str2 = str1.Trim(delim.ToCharArray());

	Console.WriteLine("Delimiters:      {0}", delim);
	Console.WriteLine("Original string: {0}", str1);
	Console.WriteLine("Trimmed string:  {0}", str2);
    }
}

import System.*;

class StringTrim2
{
    public static void main(String[] args)
    {
        String str1 = "*;|@123***456@|;*";
        String delim = "*;|@";
        String str2 = str1.Trim(delim.ToCharArray());

        Console.WriteLine("Delimiters:      {0}", delim);
        Console.WriteLine("Original string: {0}", str1);
        Console.WriteLine("Trimmed string:  {0}", str2);
    } //main
} //StringTrim2

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft