Trim last 4 characters from string?

前端 未结 4 757
予麋鹿
予麋鹿 2021-01-04 10:23

How can I trim MyString to be MyStr?

Thanks, google failed again :(

4条回答
  •  囚心锁ツ
    2021-01-04 11:13

    c#

    string str = "MyString";
    Console.WriteLine(str.Substring(0, str.Length - 3));
    

    vb.net

    dim str as string = "MyString"
    Console.WriteLine(str.Substring(0, str.Length - 3))
    

    vb.net (with VB6 style functions)

    dim str as string = "MyString"
    Console.WriteLine(Mid(str, 1, len(str) - 3))
    

提交回复
热议问题