Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

C# - Remove Last Character from String in VB.NET

Mar 13, 2013
Introduction:

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#

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);
}
Method 1 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.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.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

7 comments :

Anonymous said...

gr8.. very useful. thanx for the post

Anonymous said...

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);
}

JShreds said...

Does .Remove show different efficiency to the Left funtion? So:

Dim str as string = 'foobar'
Dim retStr as string = left(str.length - 1)

ete said...

syetet

Craig Burkett said...

If you know what the last character is then this will work;

string r = "This is a string to trim".TrimEnd('.');

return r;

Anonymous said...

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);
}

Anonymous said...

thanks for whose share on this event

Give your Valuable Comments

Other Related Posts

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.