简体   繁体   English

匹配Excel电子表格单元格的第一个和最后一个字符

[英]Match The First And Last Character Of An Excel Spreadsheet Cell

I have a spreadsheet with addresses. 我有一个包含地址的电子表格。 Sometimes, those addresses are encapsulated in double-quotes. 有时,这些地址用双引号引起来。 I created a formula that I thought would work, but it isn't removing the double-quotes. 我创建了一个我认为会起作用的公式,但它并未删除双引号。 Obviously, it isn't matching the logic. 显然,这与逻辑不符。

Sample Data: 样本数据:

"194 Notch Ln."

My formula: 我的公式:

=IF(AND(RIGHT(A1)=""", LEFT(A1)="""), MID(A1, 1, LEN(A1)-1), A1)

Is there an issue with my formula? 我的公式有问题吗? Excel didn't throw up any errors. Excel没有引发任何错误。 I read that enclosing a double-quote in double-quotes would escape it (I'm using to "\\"" in PHP). 我读到用双引号引起来的双引号会使它转义(我在PHP中使用的是"\\"" )。

You should double your quotes within the quotes. 您应该在引号将引号加倍。 So instead of """ , use """" . 因此,而不是""" ,用""""

Also, Excel strings are one-based, so to grab the second character through the next-to-last character, do this: 此外,Excel字符串是基于一个字符串的,因此要通过倒数第二个字符来获取第二个字符,请执行以下操作:

=IF(AND(RIGHT(A1)="""", LEFT(A1)=""""), MID(A1, 2, LEN(A1)-2), A1)

You need to subtract 2 from the length of the string to account for the removed quotes. 您需要从字符串的长度中减去2来考虑删除的引号。

And as @jbarker2160 pointed out, SUBSTITUTE may work better for this: 正如@ jbarker2160所指出的那样, SUBSTITUTE可能对此更好地工作:

=SUBSTITUTE(A1,"""","")

Double双引号,使用:'= IF(AND(RIGHT(A1,1)=“”“”,LEFT(A1,1)=“”“”)= TRUE,MID(A1,2,LEN(A1)- 2),A1)'。

Or you could just use wild card characters as so: 或者,您可以按如下方式使用通配符:

 =IF(COUNTIF(H10,"*"&"Notch"&"*"),1,0)

You could replace "Notch" with a cell reference. 您可以将“ Notch”替换为单元格引用。 "COUNTIF" will correctly evaluate the wildcards but "IF" by itself doesn't. “ COUNTIF”将正确评估通配符,但“ IF”本身不会。 This avoids having to remove the quotes, you could use the data as is depending on what you're trying to do downstream. 这样可以避免删除引号,您可以根据要在下游执行的操作按原样使用数据。

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

相关问题 Google Spreadsheet / EXCEL]如何获取行中的最后一个值? 使用A1作为第一个单元格? - Google Spreadsheet/EXCEL] How do I get the last value in a Row? Using A1 as the first cell? Excel:如何基于单元格的第一个字符和最后四个字符创建一个新值? - Excel: How to create a new value based on the first character and last 4 characters of cell? excel vba选择单元格中的倒数第二个字符 - excel vba select second to last character in a cell Excel:字符串中的最后一个字符/字符串匹配 - Excel: last character/string match in a string 从Excel中的第一个单词中删除最后一个字符 - Remove last character from first word in excel Excel 等号作为单元格中的第一个字符 - Excel equal sign as first character in cell 在 Excel 中的单独工作表上匹配名字和姓氏 - Match First and Last names on separate sheets in Excel 如何将单元格的第一个字符与Excel中的另一个单元格组合? - How do I combine the first character of a cell with another cell in Excel? VBA excel对于表中的每一行,将电子表格中的单元格与网页表中的单元格匹配 - VBA excel For each row in table match cell in spreadsheet with cell in webpage table Excel公式查找单元格中的第一个非字母字符? - Excel formula to find the first non-alpha character in a cell?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM