Thread: Removing the last char from a string

  1. #1
    Registered User
    Join Date
    Sep 2007

    Removing the last char from a string

    I have a text box that contains a string. When I click the "backspace" button I want to remove the last character in a string. I have tried everything I can think of, and it should be working. But instead it always removes the last two characters, the various different ways I've tried. I wasn't sure if C# strings contain the null terminator or not, but I don't see that affecting it. So some how, it's removing the last character, and than overriding the new last character with the null terminator maybe? Any ideas?

    textEntryBox.Text = textEntryBox.Text.Substring(0, textEntryBox.Text.Length - 1);

  2. #2
    "I Win!" by U. Lose vart's Avatar
    Join Date
    Oct 2006
    Rishon LeZion, Israel
    I do not understand, in a regular textbox when you press backspace it removes last char without writing any code.

    Why the default behavior is not good for you?
    To be or not to be == true

  3. #3
    Confused Magos's Avatar
    Join Date
    Sep 2001
    It removes 2 because the defaults behavoiur of a textbox when backspace is pressed is to remove the character in front of the marker. Then you remove the last character. 1+1=2.

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 04:30 PM
  2. Inheritance Hierarchy for a Package class
    By twickre in forum C++ Programming
    Replies: 7
    Last Post: 12-08-2007, 04:13 PM
  3. String Manipulation problems -_-
    By Astra in forum C Programming
    Replies: 5
    Last Post: 12-13-2006, 05:48 PM
  4. lvp string...
    By Magma in forum C++ Programming
    Replies: 4
    Last Post: 02-27-2003, 12:03 AM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM