检查字符串内容? string Length Vs空字符串 [英] Checking for string contents? string Length Vs Empty String
本文介绍了检查字符串内容? string Length Vs空字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这对于编译器和检查字符串是否为空的最佳做法更有效率?
- 检查字符串的长度== 0
- 检查字符串是否为空strVar ==)
此外,答案是否取决于语言?
- C-风格字符串:
[0] == 0
。 - .NET:
.IsNullOrEmpty
。
是的,这取决于语言。Pascal类型字符串: Length = 0
。
等。
Which is more efficient for the compiler and the best practice for checking whether a string is blank?
- Checking whether the length of the string == 0
- 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屋!
查看全文