简体   繁体   English

如何使用Excel函数获取字符串的最后一个字符?

[英]How do I get the last character of a string using an Excel function?

如何使用Excel函数获取字符串的最后一个字符?

No need to apologize for asking a question! 无需为提出问题而道歉! Try using the RIGHT function. 尝试使用RIGHT功能。 It returns the last n characters of a string. 它返回字符串的最后n个字符。

=RIGHT(A1, 1)
=RIGHT(A1)  

is quite sufficient (where the string is contained in A1). 是足够的(字符串包含在A1中)。

Similar in nature to LEFT, Excel's RIGHT function extracts a substring from a string starting from the right-most character: 与LEFT类似,Excel的RIGHT函数从最右边的字符开始从字符串中提取子字符串:

SYNTAX 句法

 RIGHT( text, [number_of_characters] ) 

Parameters or Arguments 参数或参数

text 文本

The string that you wish to extract from. 您要从中提取的字符串。

number_of_characters NUMBER_OF_CHARACTERS

Optional. 可选的。 It indicates the number of characters that you wish to extract starting from the right-most character. 它表示您希望从最右侧字符开始提取的字符数。 If this parameter is omitted, only 1 character is returned. 如果省略此参数,则仅返回1个字符。

Applies To 适用于

Excel 2016, Excel 2013, Excel 2011 for Mac, Excel 2010, Excel 2007, Excel 2003, Excel XP, Excel 2000 Excel 2016,Excel 2013,Excel 2011 for Mac,Excel 2010,Excel 2007,Excel 2003,Excel XP,Excel 2000

Since number_of_characters is optional and defaults to 1 it is not required in this case. 由于number_of_characters是可选的,默认为1因此在这种情况下不需要。

However, there have been many issues with trailing spaces and if this is a risk for the last visible character (in general): 但是,尾随空格存在许多问题,如果这是最后一个可见字符的风险(通常):

=RIGHT(TRIM(A1))  

might be preferred. 可能是首选。

Looks like the answer above was a little incomplete try the following:- 看起来上面的答案有点不完整,请尝试以下方法: -

=RIGHT(A2,(LEN(A2)-(LEN(A2)-1)))

Obviously, this is for cell A2... 显然,这是针对A2的细胞......

What this does is uses a combination of Right and Len - Len is the length of a string and in this case, we want to remove all but one from that... clearly, if you wanted the last two characters you'd change the -1 to -2 etc etc etc. 这样做是使用Right和Len的组合 - Len是字符串的长度,在这种情况下,我们想删除除此之外的所有字符......很明显,如果你想要最后两个字符你会改变它-1到-2等等等

After the length has been determined and the portion of that which is required - then the Right command will display the information you need. 确定长度并确定所需的部分后 - 然后右侧命令将显示您需要的信息。

This works well combined with an IF statement - I use this to find out if the last character of a string of text is a specific character and remove it if it is. 这与IF语句结合得很好 - 我使用它来查明文本字符串的最后一个字符是否是特定字符,如果是,则将其删除。 See, the example below for stripping out commas from the end of a text string... 请参阅下面的示例,从文本字符串末尾删除逗号...

=IF(RIGHT(A2,(LEN(A2)-(LEN(A2)-1)))=",",LEFT(A2,(LEN(A2)-1)),A2)

另一种方法是:

=MID(A1, LEN(A1), 1)

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

相关问题 如何获取字符串的最后一个字符? - How do I get the last character of a string? 你如何得到java中最后一个字符串的最后一个字符? - how do u get the last character of the last string in java? 如何从最后一个“。”之后的字符串中删除最后一个字符 - How do i remove the last character from a string after the last “.” 如何从字符串sql中字符的最后一次出现获取索引? - How do I get the index from the last occurence of a character in a string sql? 如何在不使用variable_name.at()的情况下引用字符串的最后一个字符? - How do I reference the last character of a string without using variable_name.at()? 如何找到字符串的倒数第二个字符? - How do I find the second to last character of a string? 如何用VB6替换字符串中的最后一个字符? - How do I replace the last character in a string with VB6? 如何在没有“erase()”的情况下擦除字符串的最后一个字符? - How do I erase last character of a string without “erase()”? 如何从文本框中的字符串中删除最后一个字符? - How do I remove the last character from a string in a textBox? 如何使用正则表达式获取不是特定字符的字符串中的最后一个字母? - How to get the last letter in a string that is not a specific character using regex?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM