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)
Visual Basic (Declaration)
Public Function Trim ( _
ParamArray trimChars As Char() _
) As String
Dim instance As String
Dim trimChars As Char()
Dim returnValue As String
returnValue = instance.Trim(trimChars)
public string Trim (
params char[] trimChars
)
public:
String^ Trim (
... array<wchar_t>^ 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.
Imports System
_
Class stringTrim2
Public Shared Sub Main()
Dim str1 As [String] = "*;|@123***456@|;*"
Dim delim As [String] = "*;|@"
Dim str2 As [String] = str1.Trim(delim.ToCharArray())
Console.WriteLine("Delimiters: {0}", delim)
Console.WriteLine("Original string: {0}", str1)
Console.WriteLine("Trimmed string: {0}", str2)
End Sub 'Main
End Class 'stringTrim2
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);
}
}
using namespace System;
int 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