- 1,2,3,4,5
ASP.NET: Remove the last character from a string
From Wiki
Summary: Remove the last character from a string
There may be times when you have built up a delimited string of character or words, and then needed to remove the last character/delimiter from the end of the string.
Here's a simple function that you can just pass your string to and it will return the string with the last character removed:
- Imports System.Text.RegularExpressions
- Partial Class Default1
- Inherits System.Web.UI.Page
- Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
- Response.Write(RemoveLastCharacter("1,2,3,4,5,"))
- End Sub
- Private Function RemoveLastCharacter(ByVal Text As String) As String
- Return Text.Substring(0, Text.Length - 1)
- End Function
- End Class
Output:
This Hack is part of the ASP.NET Hacks collection


