spacebar question

  • Thread starter Thread starter Rob Eventine
  • Start date Start date
R

Rob Eventine

hi all,
is there a way to eliminate a 'space character' (the space bar being
pressed) from the beginning of a line?

eg:
hello
as opposed to
hello

thanks in advance
 
If you are meaning can you remove it once it is held in a string, then yes.

string s = " hello";
s = s.Trim();

If you mean in a textbox then use the Trim method on the Text property. You
will need to move the cursor afterwards so that the user isn't surprised.
Alternatively, use the KeyDown event, check for space and the selection
being at the beginning of the text box and mark it handled so the space
isn't added. You will still need to check for pasting in a space from the
clipboard though.
 
If you are meaning can you remove it once it is held in a string, then yes.

string s = " hello";
s = s.Trim();

s.TrimStart would be more accurate. Although I doubt
trailing spaces are useful.

J
 
Back
Top