Thread: Removing the last char from a string

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    119

    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?


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

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    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?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    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.
    MagosX.com

    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