Replace the last occurrence of a word in a string - C#

前端 未结 7 1920
星月不相逢
星月不相逢 2020-12-09 14:07

I have a problem where I need to replace the last occurrence of a word in a string.

Situation: I am given a string which is in this format:

7条回答
  •  执笔经年
    2020-12-09 14:53

    You have to do the replace manually:

    int i = filePath.LastIndexOf(TnaName);
    if (i >= 0)
        filePath = filePath.Substring(0, i) + filePath.Substring(i + TnaName.Length);
    

提交回复
热议问题