帆软 substitute_用SUBSTITUTE计数单元格中的项目-程序员宅基地

技术标签: python  java  数据分析  linux  正则表达式  

帆软 substitute

Do you use Excel's SUBSTITUTE function very often? It's a handy way to count items in a cell, when they're separated by commas or spaces. The examples below show different ways to use this function – have you tried the variation in the last example?

您是否经常使用Excel的SUBSTITUTE函数? 当它们之间用逗号或空格分隔时,这是一种方便的方法,可对单元格中的项目进行计数。 以下示例显示了使用此功能的不同方法-您是否在上一个示例中尝试了变体?

计算单元格中的单词 (Count Words in a Cell)

In the first example, we'll count the items in a cell, when they are separated by commas. The items are in cell A2, and this formula is entered in cell B2:

在第一个示例中,当它们之间用逗号分隔时,我们将对它们进行计数。 这些项目在单元格A2中,并且此公式在单元格B2中输入:

=LEN(A2)-LEN(SUBSTITUTE(A2,",",""))+1

= LEN(A2)-LEN(SUBSTITUTE(A2,“,”,“”))+ 1

This formula uses LEN and SUBSTITUTE to count the items.

此公式使用LEN和SUBSTITUTE来计数项目。

  1. LEN(A2) – Counts the number of characters in cell A2

    LEN(A2)–计算单元格A2中的字符数
  2. SUBSTITUTE(A2,",","") – Replace each comma with an empty string

    SUBSTITUTE(A2,“,”,“”)–用空字符串替换每个逗号
  3. LEN(SUBSTITUTE(A2,",","") – Count characters in cell A2, with all the commas are removed

    LEN(SUBSTITUTE(A2,“,”,“”)–计数单元格A2中的字符,并删除所有逗号
  4. Subtract amount 2 from amount 1, to get the number of commas

    从数量1中减去数量2,以得到逗号数
  5. Add 1, to get the number of items

    加1,得到项目数

修剪空间 (TRIM the Spaces)

If you're using space characters to separate the items in a cell, be sure to use the TRIM function, to clean up any leading, trailing, or extra spaces.

如果要使用空格字符分隔单元格中的项目,请确保使用TRIM函数清除所有前导,尾随或多余的空格。

Without TRIM, the item count could be incorrect. Here is an example without TRIM:

没有TRIM,项目计数可能不正确。 这是一个没有TRIM的例子:

=LEN(A2)-LEN(SUBSTITUTE(A2," ",""))+1

= LEN(A2)-LEN(SUBSTITUTE(A2,“”,“”))+ 1

The counts in rows 4 and 5 are too high, because of extra spaces.

由于多余的空间,第4行和第5行的计数太高。

substitutecount01

Here's the revised formula to count items in a cell with space character separators:

这是修改后的公式,用于计算带有空格字符分隔符的单元格中的项目:

=LEN(TRIM(A2))-LEN(SUBSTITUTE(TRIM(A2)," ",""))+1

= LEN(TRIM(A2))-LEN(SUBSTITUTE(TRIM(A2),“”,“”))+ 1

The counts with this formula, in column B, are correct, and the incorrect counts (with the old formula), are in column C, for comparison

用于比较的B列中此公式的计数正确,而C列中不正确的计数(具有旧公式)进行比较

substitutecount02

检查最小计数 (Check for Minimum Count)

Instead of just counting the items in the cell, you can change the end of the formula, and check for a minimum item count.

您不仅可以对单元格中的项目进行计数,还可以更改公式的结尾并检查最小项目数。

In this example, a street name is entered in column A.

在此示例中,在A列中输入街道名称。

  • There should be at least 3 items entered in the cell, such "123 Main Street".

    单元格中至少应输入3个项目 ,例如“ 123 Main Street”。

  • If there are 3 or more items, there will be 2 or more spaces.

    如果有3个或更多的项目,将有2个或更多的空格

Change the end of the formula – instead of adding 1, to get the word count, check that the number of spaces is 2 or more

更改公式的末尾–代替加1来获取单词数,请检查空格数是否为2或更大

=LEN(A2)-LEN(SUBSTITUTE(A2,",",""))>=2

= LEN(A2)-LEN(SUBSTITUTE(A2,“,”,“”))> = 2

The results are TRUE or FALSE, and you could use a formula like this as a custom rule for  data validation in a cell.

结果为TRUE或FALSE,您可以使用像这样的公式作为自定义规则来进行单元格中的数据验证

检查最小计数版本2 (Check Minimum Count Version 2)

Another way to check for a minimum word count is with this shorter formula – thanks to UniMord for suggesting it.

检查最小字数的另一种方法是使用较短的公式-感谢UniMord的建议。

Instead of checking the cell contents with LEN, the formula replaces the 2nd space character (if there is one), and then compares with the original value.

该公式不使用LEN检查单元格内容,而是替换了第二个空格字符(如果有),然后与原始值进行比较。

=TRIM(A2)<>SUBSTITUTE(TRIM(A2)," ","",2)

= TRIM(A2)<> SUBSTITUTE(TRIM(A2),“”,“”, 2 )

substitutecount05a

这个怎么运作 (How It Works)

This formula uses 2 as the 3rd argument in SUBSTITUTE, to specify which space character (instance number) to replace.

该公式使用2作为SUBSTITUTE中的第三个参数,以指定要替换的空格字符(实例号)。

substitutecount06

The second space is removed, and you can see the results of that step in column C(it's there as a demo only).

第二个空格已删除,您可以在C列中看到该步骤的结果(此处仅作为演示)。

substitutecount05

Usually, we omit the 3rd argument, so ALL instances of the text are replaced. But in this case, it's helpful to just replace the 2nd space character, as our test.

通常,我们忽略第3个参数,因此将替换文本的所有实例。 但是在这种情况下,仅替换第二个空格字符作为测试是有帮助的。

  • We want a minimum of 3 items, so there should be at least 2 space characters.

    我们至少需要3个项目,因此至少应有2个空格字符。

  • If we replace the 2nd space, the result is different from the original value

    如果替换第二个空格,结果将与原始值不同

  • So, if the original is not equal to the revised value, there are 3 or more items.

    因此,如果原件不等于修订值,则有3件或更多件。

下载样本文件 (Download the Sample File)

To download the Count Items in a Cell sample file, go to the Excel Files page on my Contextures website. In the Functions section, look for FN0053 - Check Item Count with SUBSTITUTE

要下载单元格样本文件中的计数项目,请转到Contextures网站上的Excel Files页面。 在“功能”部分中,查找“ FN0053-用SUBSTITUTE检查项目计数”

There are more SUBSTITUTE examples on my Contextures Blog., with a workbook that you can download, to try the examples from that article.

我的Contextures博客上还有更多SUBSTITUTE实例 ,您可以下载一个工作簿来尝试该文章中的实例。

翻译自: https://contexturesblog.com/archives/2018/01/11/count-items-in-a-cell-with-substitute/

帆软 substitute

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/culiao2169/article/details/107986595

智能推荐

spring-cloud-hystrix之spring-cloud-1.3.4(Dalston.SR3)-boot(1.5.6) 学习笔记_springcloud dalston.sr3怎么引用-程序员宅基地

文章浏览阅读341次。spring-cloud-hystrix之spring-cloud-1.3.4(Dalston.SR3)-boot(1.5.6) 学习笔记概述hystrix可单独使用,也可与feign搭配使用,详见HystrixTargeter参考 https://fangjian0423.github.io/2017/02/19/springcloud-hystrix/http://blog.csdn.n_springcloud dalston.sr3怎么引用

ubuntu下将本地vscode编辑器通过ssh和远程服务器进行连接并使用远程的Python环境_ubuntu 通过 ssh 连接到远程服务器方便编辑代码的工具-程序员宅基地

文章浏览阅读991次。前言:在程序员的日常开发工作中,会遇到这样的情况,我们需要用自己本地的工作笔记本连接到大的服务器进行开发,因为大服务器的硬件性能强悍,有很多软件环境。我们在自己的笔记本进行开发需要用到这些软硬件环境,尤其在深度学习项目开发过程中,需要非常好的显卡,而显卡资源一般都部署在大服务器上。下面讲具体步骤:ssh和vscode的安装不再赘述,网上有很多教程。1,打开vscode编辑器,进入"扩展:商店":在搜索框里搜索Remote-SSH,下载好这个插件。2,点击左下角绿色部分"打开远程窗口",出现下图内容_ubuntu 通过 ssh 连接到远程服务器方便编辑代码的工具

GPU加速在前端的应用-程序员宅基地

文章浏览阅读3.2k次,点赞4次,收藏13次。概述GPU(Graphics Processing Unit) 图形处理单元,又称图形处理器,是我们所周知的显卡的核心部件,是显卡的“心脏”。按照字面意..._前台应用加速核心

C#串口通信从入门到精通(11)——串口接收的数据存储到本地文件(txt、csv)_读取并保存串口发送来的数据-程序员宅基地

文章浏览阅读4.3k次,点赞5次,收藏18次。本文详细介绍如何将串口通信将数据进行本次存储,主要介绍常用的csv、txt格式文件,由多年实战经验总结,绝对干货!_读取并保存串口发送来的数据

synchronized锁住的是什么?_如果为put方法加synchronized锁,锁住的是什么?是一个put还是所有put方法?-程序员宅基地

文章浏览阅读229次。对象锁:同步方法锁住的是对象A.一个对象+有多个synchronized方法:某一时刻内,只要有一个线程去调用其中一个synchronized 方法,其他的线程都要等待。B.一个对象中+synchronized方法+非synchronized方法:某个线程访问同步方法不影响其他线程访问非同步方法C.多个对象+多个同步方法:访问不同的对象的同步方法不会相互影响全局锁:静态同步方法锁的是当前的..._如果为put方法加synchronized锁,锁住的是什么?是一个put还是所有put方法?

outlook邮箱邮件内容乱码_邮件标题乱码问题解决一例-程序员宅基地

文章浏览阅读2.5k次。最近有用户反馈在mac下通过airmail、outlook这样的邮件客户端查看系统发出邮件的标题显示为乱码,但是windows下正常。通过邮件客户端保存为eml,用sublime text 2打开,可以发现展示为以下效果:Date: Wed, 01 Jul 2015 19:54:57 +0800From: To: "=?GBK?B?zt6+zA==?=" Subject: [MTLÑз¢Ö§³Å..._outlook 2013 转发邮件 乱码

随便推点

PLM助力国防军工制造业工艺数字化-程序员宅基地

文章浏览阅读192次。1制造业数字化工艺目标1) 通过PLM项目的实施能够理顺企...

攻防_漏洞_文件包含_文件包含漏洞详解_ctf 文件包含-程序员宅基地

文章浏览阅读3.7k次,点赞5次,收藏17次。文件包含漏洞详解_ctf 文件包含

javaweb-java占位符的使用_%x java-程序员宅基地

文章浏览阅读970次。文章目录java占位符具体使用搭配转换符的标志java占位符拼接字符串显示十分麻烦,因此java中存在大量占位符用来规范输出诸如:String.format("0.5(-%d)+", i),类似c语言的printf方法,比“0.5(-”+…更加简洁易懂String类的format()方法具体使用format(String format, Object… args) 新字符串使用本地语言环境,制定字符串格式和参数生成格式化的新字符串。format(Locale locale, String fo_%x java

【深度学习基础】反向传播BP算法原理详解及实战演示(附源码)_反向传播算法-程序员宅基地

文章浏览阅读2.8k次,点赞34次,收藏48次。【深度学习基础】反向传播BP算法原理详解及实战演示(附源码)_反向传播算法

Linux—Ubuntu12.04下安装tree_下载tree-程序员宅基地

文章浏览阅读1.6k次,点赞2次,收藏4次。Linux—Ubuntu12.04下安装tree1、下载tree安装包,命令:wget http://mama.indstate.edu/user/ice/tree/src/tree-1.7.0.tgz2、解压tree安装包,命令:tar -zxvf tree-1.7.0.tgz3、 进入解压目录,命令:cd tree-1.7.04、 安装文件,命令:make install5、 测试使用,命令:tree亲测有效!详见转载:我用#CSDN#这个app发现了有技术含量的博客,小伙伴们求同去《L_下载tree

Excel中vlookup模糊查找的妙用(模糊匹配)_vlookup关键字模糊匹配-程序员宅基地

文章浏览阅读5k次,点赞2次,收藏4次。查找数据是否存在与另一个单元格区域中_vlookup关键字模糊匹配

推荐文章

热门文章

相关标签