什么是空字符串的目的是什么?目的、空字符串

由网友(囚你无期)分享简介:在我看来,作为一个开发者,并作为一个用户,我发现一个空字​​符串()无用和许多混乱的原因,这好像是说字符串==的char [] 也许计算机需要空字符串,所以我想知道为什么。参见:默认字符串初始化:null或空 Best做法:?如果函数返回null或一个空对象 解决方案 有人可能会争辩说,空字符串是的空对象模式的。安东尼...

在我看来,作为一个开发者,并作为一个用户,我发现一个空字​​符串()无用和许多混乱的原因,这好像是说字符串==的char []

也许计算机需要空字符串,所以我想知道为什么。

  

参见:

         默认字符串初始化:null或空    Best做法:?如果函数返回null或一个空对象    解决方案

有人可能会争辩说,空字符串是的空对象模式的。安东尼指出,这是为了避免特殊情况和大量的如果秒。

To me, as a developer and as a user, I find the empty string ("") useless and the cause of much confusion, it's like saying string == char[]

Maybe computers need the empty string, so I'd like to learn why.

See also:

Default string initialization: NULL or Empty? Best Practice: Should functions return null or an empty object? C语言题目 目的是插入空格在字符串中 显示int到char截断怎么处理 以及程序怎么修改 谢谢谢

解决方案

One could argue that the empty string is an instance of the Null Object Pattern. As Anthony pointed out, this is used to avoid special cases and lots of ifs.

阅读全文

相关推荐

最新文章