Introduction:
Here I will explain how to remove last character from string in c#, vb.net using asp.net.
Here I will explain how to remove last character from string in c#, vb.net using asp.net.
Description:
In previous posts I explained jQuery Remove first or last characters from string, Delete selected rows from datatable in c#, vb.net, jQuery get number of facebook likes, shares, comments count for url 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 using asp.net.
To implement this functionality we have different methods
Method 1 in C#
In previous posts I explained jQuery Remove first or last characters from string, Delete selected rows from datatable in c#, vb.net, jQuery get number of facebook likes, shares, comments count for url 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 using asp.net.
To implement this functionality we have different methods
Method 1 in C#
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 in C#
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);
}
|
Method 2 in 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
|
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. |
|||
|
|||
9 comments :
gr8.. very useful. thanx for the post
Hello Suresh, If I want to remove the last character specially, will the following code be more appropriate?
protected void Page_Load(object sender, EventArgs e)
{
string istr = "1,2,3,4,5,6,7,8,9,10,";
string ostr = istr.TrimEnd(",".ToCharArray());
Response.Write(ostr);
}
Does .Remove show different efficiency to the Left funtion? So:
Dim str as string = 'foobar'
Dim retStr as string = left(str.length - 1)
syetet
If you know what the last character is then this will work;
string r = "This is a string to trim".TrimEnd('.');
return r;
Method 2 in C#
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);
}
in this you dont need to write .ToCharArray() I think.
You can write
Method 2 in C#
protected void Page_Load(object sender, EventArgs e)
{
string istr = "1,2,3,4,5,6,7,8,9,10,";
string ostr = istr.TrimEnd(",");
Response.Write(ostr);
}
thanks for whose share on this event
thnks
Note: Only a member of this blog may post a comment.