spacebar question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rob Eventine

    spacebar question

    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




  • BlackWasp

    #2
    Re: spacebar question

    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.

    --

    BlackWasp



    "Rob Eventine" <btb101@ntlworl d.comwrote in message
    news:AIorj.9015 $j95.5736@newsf e3-win.ntli.net...
    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
    >
    >
    >
    >

    Comment

    • Jan Hyde (VB MVP)

      #3
      Re: spacebar question

      "BlackWasp" <nospam@please> 's wild thoughts were released on
      Sun, 10 Feb 2008 02:08:23 -0000 bearing the following fruit:
      >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
      >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.
      >Alternativel y, 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.
      --
      Jan Hyde


      Comment

      Working...