Introduction:
Here I will explain how to remove last character from string in c#, vb.net with example or delete or remove last character in string with examples in c#, vb.net. In c# or vb.net we can easily remove last character from string by using Remove or Trim or IndexOf properties.
Here I will explain how to remove last character from string in c#, vb.net with example or delete or remove last character in string with examples in c#, vb.net. In c# or vb.net we can easily remove last character from string by using Remove or Trim or IndexOf properties.
Description:
In previous posts I explained send list as parameter to function with example, check if arraylist contains specific string or not, jQuery display image based on the url entered, jQuery Remove first or last characters from string, Delete selected rows from datatable in c#, vb.net and many articles relating to Asp.net, Gridview, Ajax, JQuery. Now I will explain how to remove last character from string in c#, vb.net with example.
We have different ways to remove the last character from string in c#, vb.net based on our requirements.
Following are the few methods which we can use to remove last character from string.
In previous posts I explained send list as parameter to function with example, check if arraylist contains specific string or not, jQuery display image based on the url entered, jQuery Remove first or last characters from string, Delete selected rows from datatable in c#, vb.net and many articles relating to Asp.net, Gridview, Ajax, JQuery. Now I will explain how to remove last character from string in c#, vb.net with example.
We have different ways to remove the last character from string in c#, vb.net based on our requirements.
Following are the few methods which we can use to remove last character from string.
Method 1
Following is the
one way of removing last character from string using Remove property
C# Code
protected void
Page_Load(object sender, EventArgs e)
{
string istr = "1,2,3,4,5,6,7,8,9,10,";
string ostr = istr.Remove(istr.Length - 1,
1);
Response.Write(ostr);
}
|
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim istr As
String = "1,2,3,4,5,6,7,8,9,10,"
Dim ostr As
String = istr.Remove(istr.Length - 1, 1)
Response.Write(ostr)
End Sub
|
Method 2
Following
is the another way of removing last character from string using Trim property
C# Code
protected void
Page_Load(object sender, EventArgs e)
{
string istr = "1,2,3,4,5,6,7,8,9,10,";
string ostr = istr.Trim(",".ToCharArray());
Response.Write(ostr);
}
|
VB.NET
Protected Sub
Page_Load(ByVal sender As Object, ByVal e As
EventArgs) Handles Me.Load
Dim istr As String = "1,2,3,4,5,6,7,8,9,10,"
Dim ostr As String = istr.Trim(",".ToCharArray())
Response.Write(ostr)
End Sub
|
Method 3
Following
is the another way of removing the last character from string using IndexOf property but that character
should exists only one time otherwise this property will return the values
before the first character.
C# Code
protected void
Page_Load(object sender, EventArgs e)
{
string istr = "aspdotnet-suresh.com,";
string ostr = istr.Remove(istr.IndexOf(","));
Response.Write(ostr);
}
|
VB.NET
Protected Sub
Page_Load(ByVal sender As Object, ByVal e As
EventArgs) Handles Me.Load
Dim istr As String = "aspdotnet-suresh.com,"
Dim ostr As String = istr.Remove(istr.IndexOf(","))
Response.Write(ostr)
End Sub
|
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
|
|||
0 comments :
Note: Only a member of this blog may post a comment.