使用c#语言 获取字符串的最后一位作为子字符串
可以使用Substring方法来获取字符串的最后一位作为子字符串。可以使用以下代码实现:
string str = "Hello World!";
string subStr = str.Substring(str.Length - 1);
Console.WriteLine(subStr); // 输出 "!"
// 或者可以使用下面的代码来获取字符串的最后一位作为字符
char lastChar = str[str.Length - 1];
Console.WriteLine(lastChar); // 输出 "!"
在这个例子中,我们定义了一个字符串str,然后使用Substring方法来获取字符串的最后一位字符。另外,我们也可以直接通过索引来获取字符串的最后一位字符。
原文地址: http://www.cveoy.top/t/topic/iiZO 著作权归作者所有。请勿转载和采集!