# SUBSTR

> Return a substring of a string; an older name for GETRANGE.

URL: https://docs.hotkv.com/commands/substr/

```
SUBSTR key start end
```

- Group: String
- Complexity: O(N) where N is the length of the returned substring
- HotKV Cloud: all plans
- On-Premise: no license needed
- Deprecated: use GETRANGE instead

`SUBSTR` is an older name for [GETRANGE](https://docs.hotkv.com/commands/getrange/index.md) and behaves the
same way: it returns the bytes from `start` to `end`, both included, with
negative offsets counting from the end. Use `GETRANGE` in new code.

## Return value

| Case | RESP2 | RESP3 |
| --- | --- | --- |
| Always | Bulk string: the substring (possibly empty) | Bulk string |

The errors are those of [GETRANGE](https://docs.hotkv.com/commands/getrange/index.md).

## Examples

```
127.0.0.1:6379> SET phrase "hotkv rocks"
OK
127.0.0.1:6379> SUBSTR phrase 0 4
"hotkv"
```

## Compatibility

Same as Redis 7 and Valkey 8, where it is also deprecated.

## See also

[GETRANGE](https://docs.hotkv.com/commands/getrange/index.md), [STRLEN](https://docs.hotkv.com/commands/strlen/index.md)