How to remove a defined part of a string?

前端 未结 8 1895
死守一世寂寞
死守一世寂寞 2021-01-07 18:19

I have this string: \"NT-DOM-NV\\MTA\" How can I delete the first part: \"NT-DOM-NV\\\" To have this as result: \"MTA\"

How is it possible with RegEx?

8条回答
  •  攒了一身酷
    2021-01-07 18:39

    If there is always only one backslash, use this:

    string result = yourString.Split('\\').Skip(1).FirstOrDefault();
    

    If there can be multiple and you only want to have the last part, use this:

    string result = yourString.SubString(yourString.LastIndexOf('\\') + 1);
    

提交回复
热议问题