[英]Excel string comparisons with escape character, using boolean, match or sumif
When I was handeling a text-comparison in my database I noticed some odd behavior. 当我在数据库中进行文本比较时,我注意到一些奇怪的行为。 In my database I want to SUM values based on a column containing strings.
在我的数据库中,我想基于包含字符串的列求和。 In this example, I want to make a group
str
and a group txt
, with the following string values. 在此示例中,我想使用以下字符串值创建一个
str
组和一个txt
组。
str 2
str1 1
str2 0
txt 1
txt1 2
tx2 3
If I would compare the text with a simpel boolean, ie =("str"="str*"), it returns False
, because the *
is an additional character. 如果我将文本与simpel布尔值(即=(“ str” =“ str *”))进行比较,则会返回
False
,因为*
是附加字符。 This makes sense in some way. 这在某种意义上是有意义的。 However, when I used two other techniques the comparison is handled differently:
但是,当我使用其他两种技术时,比较的处理方式有所不同:
First, the following simple SUMIFS function: =SUMIFS(B:B;A:A;"str*")
and =SUMIFS(B:B;A:A;"txt*")
includes the values at "str" and "txt" respectively, suggesting the comparison is True
. 首先,以下简单的SUMIFS函数:
=SUMIFS(B:B;A:A;"str*")
和=SUMIFS(B:B;A:A;"txt*")
包含“ str”和“ txt”,表明比较为True
。
Second, =Match("str*";{Cell containing "str"};0)
returns 1, indicating that the comparison also returns True
. 其次,
=Match("str*";{Cell containing "str"};0)
返回1,指示比较也返回True
。
Why does the boolean string comparison return False
, whilst MATCH
and SUMIFS
assume True
? 为什么布尔字符串比较返回
False
,而MATCH
和SUMIFS
假定为True
?
Only a limited number of Excel worksheet functions can use wildcard characters to filter results. 仅有限数量的Excel工作表函数可以使用通配符来过滤结果。 Functions like
COUNTIF
, VLOOKUP
, MATCH
and others as listed here are some Excel functions that use wildcards. 像功能
COUNTIF
, VLOOKUP
, MATCH
等,作为上市这里是使用通配符一些Excel函数。
Apart from the functions listed in the link, wildcard *
is treated like a literal when used in the double quotes. 除链接中列出的功能外,在双引号中使用通配符
*
其含义与文字相同。
In my opinion those two functions apply the wildcard interpretation of the asterisks while your direct comparison formula with '=' takes it as just another (extra) character in the string inside the quotes, so making the two strings different. 在我看来,这两个函数均采用星号的通配符解释,而带有'='的直接比较公式会将其当作引号内字符串中的另一个字符(额外),从而使两个字符串不同。
While in the function Match(): If match_type is 0 and lookup_value is text, lookup_value can contain the wildcard characters asterisk (*) and question mark (?). 在函数Match()中时:如果match_type为0并且lookup_value为text,则lookup_value可以包含通配符星号(*)和问号(?)。 An asterisk matches any sequence of characters;
星号匹配任何字符序列; a question mark matches any single character.
问号与任何单个字符匹配。
I hope this makes sense. 我希望这是有道理的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.