Home > Web Front-end > JS Tutorial > body text

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

WBOY
Release: 2016-05-16 17:26:51
Original
1146 people have browsed it

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!