Check if it contains characters in the string

-1

When I use% w / o, it returns me the size, but how do I check if it does not contain any characters?

For example:

var teste = (como se o usuário tivesse clicado **2x** no **enter/espaço**); 

Soon teste.length will return 2 , but does not actually contain any characters.

I wish that when I had nothing, I would return 0.

    
asked by anonymous 09.11.2018 / 15:11

2 answers

3

Use trim() .

stringExemplo = stringExemplo.trim(); it removes the whitespace. You can use str.replace as well.

    
09.11.2018 / 15:14
2

Use trim() , so spaces will be disregarded at the beginning and end of the string .

var teste = string_usada.trim();
    
09.11.2018 / 15:14