一段$ string太长了......太长了... javascript P2

时间:2010-06-05 02:50:27

标签: php javascript

如何将此PHP代码转换为JavaScript?

$string = "string How Long is a Piece of String?";

if (strlen($string) < 5)
{
   echo "string is less than 5";
}
else
{
   echo "string is more than 5";
}

1 个答案:

答案 0 :(得分:4)

我认为这只是一个非常复杂,错误解释,错误拼写的方式,询问如何在JavaScript中获取字符串的长度。如果是这种情况,只需检查字符串的length属性,如下所示:

var str = 'How long is a piece of string?';
if (str.length < 5) {
  alert('String is less than 5');
} else {
  alert('String is greater than or equal to 5');
}

如果这不是你要求的,你真的需要澄清这个问题。