How to limit letter of WordPress post title

How to limit letter of WordPress post title? Just replace this code

with the following code.

This code is very helpful to limit WordPress post title.