检查动作脚本中的字符串是否为空,类似于.net中的String.Empty

发布于 2025-01-06 10:43:50 字数 79 浏览 3 评论 0原文

Action中是否有一个类似于.net中String对象中的静态属性来检查字符串是否为空,那就是String.Empty。

谢谢

Is there a static property in Action similar to that in the String object in .net to check if a string is empty, that is String.Empty.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

扮仙女 2025-01-13 10:43:50

您可以简单地执行以下操作:

if(string) 
{
    // String isn't null and has a length > 0
}
else
{
   // String is null or has a 0 length
}

这有效,因为使用这些规则:

字符串-> Boolean = "如果值为 null 或空字符串 ( "" ),则为 false;否则为 true。"

You can simply do:

if(string) 
{
    // String isn't null and has a length > 0
}
else
{
   // String is null or has a 0 length
}

This works because the string is coerced to a boolean value using these rules:

String -> Boolean = "false if the value is null or the empty string ( "" ); true otherwise."

待天淡蓝洁白时 2025-01-13 10:43:50

以下将捕获所有这些:

  1. NULL
  2. 空字符串
  3. 仅空白字符串

import mx.utils.StringUtil;

var str:String

if(!StringUtil.trim(str)){
   ...
}

The following will catch all of these:

  1. NULL
  2. empty string
  3. whitespace only string

import mx.utils.StringUtil;

var str:String

if(!StringUtil.trim(str)){
   ...
}
只等公子 2025-01-13 10:43:50

您可以使用 length 但这是一种普通属性而不是静态属性。您可以在此处找到该类的所有属性 String< /a>.如果长度为0,则字符串为空。因此,如果您想区分 null 字符串和空字符串,可以按如下方式进行测试:

if (!myString) {
   // string is null
} else if (!myString.length) {
   // string is empty
} else {
   // string is not empty
}

或者,如果您不需要区分空字符串和空字符串,则可以使用 Richie_W 的解决方案。

You can use length but that is a normal property not a static one. You can find here all the properties of of the class String. If length is 0 the string is empty. So you can do your tests as follows if you want to distinguish between a null String and an empty one:

if (!myString) {
   // string is null
} else if (!myString.length) {
   // string is empty
} else {
   // string is not empty
}

Or you can use Richie_W's solution if you don't need to distinguish between empty and null strings.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文