Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Community Wiki

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Navigation

Google Ads

ASP.NET: Remove the last character from a string

From Wiki

Jump to: navigation, search

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:

  1. Imports System.Text.RegularExpressions
  2. Partial Class Default1
  3.     Inherits System.Web.UI.Page
  4.  
  5.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  6.         Response.Write(RemoveLastCharacter("1,2,3,4,5,"))
  7.     End Sub
  8.  
  9.     Private Function RemoveLastCharacter(ByVal Text As String) As String
  10.         Return Text.Substring(0, Text.Length - 1)
  11.     End Function
  12. End Class

Output:


This Hack is part of the ASP.NET Hacks collection

482 Rating: 3.3/5 (11 votes cast)