How to get the first five character of a String

后端 未结 20 2361
醉酒成梦
醉酒成梦 2020-12-01 05:01

I have read this question to get first char of the string. Is there a way to get the first n number of characters from a string in C#?

20条回答
  •  一向
    一向 (楼主)
    2020-12-01 05:22

    I don't know why anybody mentioned this. But it's the shortest and simplest way to achieve this.

    string str = yourString.Remove(n);
    

    n - number of characters that you need

    Example

    var zz = "7814148471";
    Console.WriteLine(zz.Remove(5));
    //result - 78141
    

提交回复
热议问题