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

后端 未结 11 1803
误落风尘
误落风尘 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:40

    You could make your own:

    private string left(string inString, int inInt)
    {
        if (inInt > inString.Length)
            inInt = inString.Length;
        return inString.Substring(0, inInt);
    }
    

    Mine is in C#, and you will have to change it for Visual Basic.

提交回复
热议问题