How do I get the last four characters from a string in C#?

前端 未结 20 1096
陌清茗
陌清茗 2020-11-30 18:13

Suppose I have a string:

\"34234234d124\"

I want to get the last four characters of this string which is \"d124\". I can use <

20条回答
  •  一个人的身影
    2020-11-30 18:43

    Update 2020: C# 8.0 finally makes this easy:

    > "C# 8.0 finally makes this easy"[^4..]
    "easy"
    

    You can also slice arrays in the same way, see Indices and ranges.

提交回复
热议问题