Also if you need such a method it's already present in Symfony\Component\Security\Core\Util\StringUtils