.NET equivalent of the old vb left(string, length) function

后端 未结 11 1817
误落风尘
误落风尘 2020-12-02 17:50

As a non-.NET programmer I\'m looking for the .NET equivalent of the old Visual Basic function left(string, length). It was lazy in that it worked for any lengt

11条回答
  •  长情又很酷
    2020-12-02 18:44

    Another one line option would be something like the following:

    myString.Substring(0, Math.Min(length, myString.Length))
    

    Where myString is the string you are trying to work with.

提交回复
热议问题