简体   繁体   English

检查单元格是否紧接彼此包含2个空格

[英]Check to see if cell contains 2 spaces directly after each other

Is there a way that I can check to see if my cell contains 2 spaces immediately after one another? 有没有一种方法可以检查我的单元格是否紧挨着包含两个空格?

For example if my cell contained "The cat went meow" then my formula below will return "No" because there is only one space between each character. 例如,如果我的单元格包含"The cat went meow"则我的下面的公式将返回"No"因为每个字符之间只有一个空格。 However, if there where 2 spaces like 但是,如果有2个空格

"The cat  went meow"

then the formula would return "Yes" . 然后公式将返回"Yes"

I have tried the following formula but it picks up all the spaces instead of what I want it to do. 我尝试了以下公式,但是它占用了所有空间,而不是我想要的空间。 Can someone please show me how i could correct this? 有人可以告诉我如何纠正这个问题吗?

=IF(ISNUMBER(SEARCH(" " & " ",B1)),"Yes","no")

Might be worth considering TRIM() : 可能值得考虑TRIM()

=LEN(B1)=LEN(TRIM(B1))  

Test cases: 测试用例:

"The cat went meow"    TRUE    (single space)
"The cat  went meow"   FALSE   (double space)
" The cat went meow"   FALSE   (leading space)
"The cat went meow "   FALSE   (trailing space)

this works for your example, if allowance is made for returning T/F rather than Y/N (to keep the formula short - Y/N could be arranged). 如果您允许返回T / F而不是Y / N(为了使公式简短-可以安排Y / N),则此示例适用于您的示例。

A better (shorter) version was offered by @Rick Hitchcock (to whom thanks) in a Comment: @Rick Hitchcock (感谢他)在评论中提供了一个更好(更短)的版本:

=B1=TRIM(B1)

However it would return FALSE not only for "double" spaces but any quantity of spaces that are not on their own (immediately next to characters on both sides) 但是,它不仅会对“双精度”空格返回FALSE,还会对不属于自己的任何数量的空格(紧挨着两侧的字符)返回FALSE。

and

it would return FALSE even for single spaces if at the start and/or end of your string. 如果在字符串的开头和/或结尾,则即使对于单个空格也将返回FALSE。

So this is not exactly what you asked for, and no more, but in practice seems likely to be more useful in general. 因此,这并不是您所要的,也不再是您所要的,但实际上,它通常似乎更有用。

Your code works for me as-is. 您的代码按原样对我有用。 You could simplify it like this: 您可以像这样简化它:

=IF(ISNUMBER(SEARCH("  ",B1)),"Yes","no")

To avoid error-checking, you could compare the string to a version with double-spaces converted to spaces, like this: 为了避免错误检查,您可以将字符串与具有双精度空格的版本进行比较,如下所示:

=IF(SUBSTITUTE(B1,"  "," ")<>B1,"Yes","no")

But I'm unsure what problem you're having with your existing code. 但是我不确定您现有的代码有什么问题。

Try this 尝试这个

    =IF(ISERROR(FIND("  ",B1,1)),"No","Yes")

or 要么

    =IF(ISERROR(SEARCH("  ",B1,1)),"No","Yes")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM