> For the complete documentation index, see [llms.txt](https://trizen.gitbook.io/sidef-lang/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://trizen.gitbook.io/sidef-lang/programming_tasks/s/substring/top_and_tail.md).

# Top and tail

Strip any characters:

```ruby
say "knight".substr(1)        # strip first character
say "socks".substr(0, -1)     # strip last character
say "brooms".substr(1, -1)    # strip both first and last characters
say "与今令".substr(1, -1)     # => 今
```

#### Output:

```
night
sock
room
今
```

Strip graphemes:

```ruby
var gstr = "J\x{332}o\x{332}s\x{332}e\x{301}\x{332}"
say gstr-/^\X/                     # strip first grapheme
say gstr-/\X\z/                    # strip last grapheme
say gstr.sub(/^\X/).sub(/\X\z/)    # strip both first and last graphemes
```

#### Output:

```
o̲s̲é̲
J̲o̲s̲
o̲s̲
```
