[已解决] 求助Matlab字符串中'空'的理解

[复制链接]
Watermarker 发表于 7 天前
  1. >>  count('apple',' ')
  2. ans =
  3.      0
  4. >> count('abc','')
  5. ans =
  6.      4
复制代码
麻烦问下各位大神第二句语句结果为什么是4?

最佳答案


TouAkira 发表于 5 天前
去看《 Test for Empty Strings and Missing Value(超链接,自己点进去看) 》中Find Empty Strings Within Other Strings一节给出的解释
Strings always contain the empty string as a substring. In fact, the empty string is always at both the start and the end of every string. Also, the empty string is always found between any two consecutive characters in a string.

Count the number of characters in str. Then count the number of empty strings in str. The count function counts empty strings at the beginning and end of str, and between each pair of characters. Therefore if str has N characters, it also has N+1 empty strings.
回复此楼

1 条回复


TouAkira 发表于 5 天前
去看《 Test for Empty Strings and Missing Value(超链接,自己点进去看) 》中Find Empty Strings Within Other Strings一节给出的解释
Strings always contain the empty string as a substring. In fact, the empty string is always at both the start and the end of every string. Also, the empty string is always found between any two consecutive characters in a string.

Count the number of characters in str. Then count the number of empty strings in str. The count function counts empty strings at the beginning and end of str, and between each pair of characters. Therefore if str has N characters, it also has N+1 empty strings.
回复此楼
您需要登录后才可以回帖 登录 | 注册

本版积分规则

相关帖子
相关文章
热门教程
站长推荐
快速回复 返回顶部 返回列表