我想找到字符串的最后一个字符,然后放入if
中,说明如果最后一个字符等于“A”,“B”或“C”,则可以执行某些操作。如何获得最后一个角色?
最佳答案
使用字符串的endswith
方法:
if (string.EndsWith("A") || string.EndsWith("B"))
{
//do stuff here
}
这是MSDN文章,介绍了此方法:
http://msdn.microsoft.com/en-us/library/system.string.endswith(v=vs.71).aspx
关于c# - 如何在C#中检查字符串的最后一个字符?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14794267/