# Last character in a string?

**URL:** <https://forum.kirupa.com/t/last-character-in-a-string/302660>\
**Category:** flash\
**Created:** [January 5, 2010, 9:56am UTC](https://forum.kirupa.com/t/last-character-in-a-string/302660 "2010-01-05T09:56:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Signy](https://avatars.discourse-cdn.com/v4/letter/s/5e9695/32.png) [@Signy](https://forum.kirupa.com/u/Signy)\
**Post date:** [January 5, 2010, 9:56am UTC](https://forum.kirupa.com/t/last-character-in-a-string/302660/1 "2010-01-05T09:56:14Z")

</div>

Hi all,

Recently made the transition from flash/as2 to flex/as3 have to say I’m loving it! Thought i’d experiment a bit and test the water making a simple live chat application already run into my first snag.

```auto
private function keyPressed(e:KeyboardEvent):void
        {
            switch(e.keyCode)
            {
                case 13:
                    sendText();
                break;
            }
        }
private function sendText():void
        {
            if(inputText.text == "")
            {
                trace("text field is blank");
            }else{
                textDisplay.appendText(inputText.text + "
");
                inputText.text = "";
                stage.focus = inputText;
            }
        }

```

This is called using:

```auto
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);

```

The problem I’m experiencing is when you first hit enter and add the text to the display box is registers the enter and adds it aswell.

```auto
textDisplay.appendText(inputText.text + "
");

```

This is the main offender. I’m just wondering how I would find the last character and ignore everything else after that? Kind of similar to the php explode.

Heres a picture to better demonstrate:

![](http://img35.imageshack.us/img35/6004/examplepi.jpg)

Ta Sigs
