Removing the last char from a string

This is a discussion on Removing the last char from a string within the C# Programming forums, part of the General Programming Boards category; I have a text box that contains a string. When I click the "backspace" button I want to remove the ...

  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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,424
    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?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  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, 03:13 PM
  3. String Manipulation problems -_-
    By Astra in forum C Programming
    Replies: 5
    Last Post: 12-13-2006, 04:48 PM
  4. lvp string...
    By Magma in forum C++ Programming
    Replies: 4
    Last Post: 02-26-2003, 11:03 PM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21