你可以使用 LastIndexOf 方法找到最后一个.的索引,然后使用 Substring 方法截取字符串的前部分和后部分,并将它们拼接起来,再加上,。以下是一个示例代码:

string input = "Hello.World.";
int lastDotIndex = input.LastIndexOf(".");
if (lastDotIndex >= 0)
{
    string result = input.Substring(0, lastDotIndex) + "," + input.Substring(lastDotIndex + 1);
    Console.WriteLine(result);
}
else
{
    Console.WriteLine(input);
}

上述代码的输出将会是 Hello,World.

c# 把一个字符串中 最后一个替换成

原文地址: https://www.cveoy.top/t/topic/hNL0 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录