检查字符串内容? string Length Vs空字符串 [英] Checking for string contents? string Length Vs Empty String

查看:144
本文介绍了检查字符串内容? string Length Vs空字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这对于编译器和检查字符串是否为空的最佳做法更有效率?


  1. 检查字符串的长度== 0

  2. 检查字符串是否为空strVar ==)

此外,答案是否取决于语言?




    是的,这取决于语言。Pascal类型字符串: Length = 0

  • C-风格字符串: [0] == 0

  • .NET: .IsNullOrEmpty



等。


Which is more efficient for the compiler and the best practice for checking whether a string is blank?

  1. Checking whether the length of the string == 0
  2. Checking whether the string is empty (strVar == "")

Also, does the answer depend on language?

解决方案

Yes, it depends on language, since string storage differs between languages.

  • Pascal-type strings: Length = 0.
  • C-style strings: [0] == 0.
  • .NET: .IsNullOrEmpty.

Etc.

这篇关于检查字符串内容? string Length Vs空字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆