Excel 具有特定开头和结尾的字符串的可变长度子字符串
我必须从excel中的字符串(单元格)中间提取一个子字符串,该子字符串的长度总是可变的 标准是:Excel 具有特定开头和结尾的字符串的可变长度子字符串,excel,string,excel-formula,Excel,String,Excel Formula,我必须从excel中的字符串(单元格)中间提取一个子字符串,该子字符串的长度总是可变的 标准是: 它总是以一组特定的符号开始(在本例中为“成分:”) 它总是以一组特定的符号结束(在本例中为“营养信息表”) 长度可以是从1个单词到大约500个单词的任意长度 它可以是excel公式,甚至是VBA。但是我是VBA的初学者,所以请给出具体的建议 我的示例单元格内容如下所示: We could tell you that our Beanz are hard to beat. That the
- 它总是以一组特定的符号开始(在本例中为“成分:”)
- 它总是以一组特定的符号结束(在本例中为“营养信息表”)
We could tell you that our Beanz are hard to beat. That they're brimming with deliciously rich, tomatoey flavour. But you already know that. Because you know what Beanz Meanz...
Heinz baked beans don't just taste great, but are nutritious too; high in fibre, high in protein and low in fat, as well as contributing to 1 of your 5 a day. Packed full of quality ingredients... it has to be Heinz. Love our Heinz Beanz as much as we do? Discover the rest of our range, including organic and no added sugar varieties!
Heinz Beanz come in a variety of multipacks, perfect for when you need to feed the whole family!
1 of your 5 a day.
No artificial colours, flavours or preservatives.
Suitable for Vegetarians and Vegans.
Naturally high in protein and fibre.
Gluten free and low in fat.
Ingredients:
Beans (51%), Tomatoes (34%), GRAIN, Water, Sugar, Spirit Vinegar, Modified Corn Flour, Salt, Spice Extracts, Herb Extract.
Suitable for Vegetarians. Free From Artificial Flavours.
Empty unused contents into a suitable covered container. Keep refrigerated and use within 2 days.
Table of Nutritional Information
Per 100g Per 1/2 can %RI*
Energy 329kJ 682kJ -
78kcal 162kcal 8%
Fat 0.2g 0.4g 1%
- of which saturates <0.1g <0.1g <1%
Carbohydrate 12.5g 25.9g 10%
- of which sugars 4.7g 9.8g 11%
Fibre 3.7g 7.7g -
Protein 4.7g 9.7g 19%
Salt 0.6g 1.2g 21%
*RI per serving. Reference intake of an average adult (8400kJ/2000kcal)
假设您的示例单元格为A1,那么在另一个单元格中,您可以执行以下操作:
=TRIM(MID(A1;SEARCH("Ingredients:";A1);SEARCH("Table of Nutritional Information";A1)-SEARCH("Ingredients:";A1)))
您可能需要进行一些调整,以消除最终特征线
这就是它的工作原理:
搜索(“成分:;A1)
将找到第一个文本的位置Ingredientes
。返回一个数字。这将是使用MID提取文本的起点搜索(“营养信息表”A1)
与之前相同,但带有文本营养信息表
。这就是提取文本的终点=TRIM(MID(A1;SEARCH("Ingredients:";A1);SEARCH("Table of Nutritional Information";A1)-5-SEARCH("Ingredients:";A1)))
这将返回您想要的确切输出,但不知道它是否适用于您的所有输入。假设源数据位于列A中,将标准标题“配料”和“营养信息表”放在
B1
和C1
中
那么
在B2
中,公式被复制下来:
=MID(LEFT($A2,FIND(C$1,$A2)-1),FIND(B$1,$A2)+LEN(B$1)+1,599)
=MID(LEFT($A2,FIND(C$1,$A2)-1),FIND(B$1,$A2)+LEN(B$1)+1,599)