Introduction : In this tutorial we will see how remove some character or string value from a given string using Remove() method of string class in .NET Framework using C# and vb.net code example.
Remove() Method of the string class is similar to Substring() Method. Using Remove() you can remove certain character from the given string.
C# Code sample: using System;
namespace DotNetSparkTutorials
{
class Program
{
static void Main(string[] args)
{
// Declare string;
string strValue = "DotNetSpark";
// return the substring of a given string after 3 character from the Remove() Method of string class
string strResultValue1 = strValue.Remove(3);
// return the whole substring of a given string starting from 3 character to 3 next characters using the Remove() Method of string class
string strResultValue2 = strValue.Remove(3, 3);
//Display the resultant sub string which stored in variable strResultValue1
Console.WriteLine(strResultValue1);
//Display the resultant sub string which stored in variable strResultValue2
Console.WriteLine(strResultValue2);
Console.ReadLine();
}
}
}
Output:
Dot DotSpark
VB.NET Code example: Namespace DotNetSparkTutorials
Class Program
Private Shared Sub Main(args As String())
' Declare string;
Dim strValue As String = "DotNetSpark"
' return the substring of a given string after 3 character from the Remove() Method of string class
Dim strResultValue1 As String = strValue.Remove(3)
' return the whole substring of a given string starting from 3 character to 3 next characters using the Remove() Method of string class
Dim strResultValue2 As String = strValue.Remove(3, 3)
'Display the resultant sub string which stored in variable strResultValue1
Console.WriteLine(strResultValue1)
'Display the resultant sub string which stored in variable strResultValue2
Console.WriteLine(strResultValue2)
Console.ReadLine()
End Sub
End Class
End Namespace
Output:
Dot DotSpark
|