Home  >  Article  >  Web Front-end  >  js simple method to determine the length of a string/judgment of empty_javascript skills

js simple method to determine the length of a string/judgment of empty_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:26:511187browse

Three methods available for calculating string length:

Copy code The code is as follows:

echo “$str” awk ‘{print length($0)}’
expr length “$str”
echo “$str”wc -c


But the The values ​​obtained by the three methods will be 1 more, possibly because the terminator is also included in the calculation.
There are three ways to determine whether a string is empty:
Copy code The code is as follows:

if [ "$str" = "" ]
if [ x"$str" = x ]
if [ -z "$str" ]

Note: You must put double quotes, otherwise some commands will report errors, so you should develop a good habit!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn