修剪字符串中的最后4个字符?

时间:2009-08-27 03:44:02

标签: vb.net

如何将MyString剪裁为MyStr?

谢谢,谷歌再次失败:(

4 个答案:

答案 0 :(得分:29)

YourString.Left(YourString.Length-4)

或:

YourString.Substring(0,YourString.Length-4) 

答案 1 :(得分:7)

Rob的回答大多是正确的,但只要字符串少于4个字符,SubString解决方案就会失败。如果长度超过字符串的结尾,则会抛出异常。以下修复问题

Public Function TrimRight4Characters(ByVal str As String) As String
  If 4 > str.Length Then
    return str.SubString(4, str.Length-4)
  Else
    return str
  End if
End Function

答案 2 :(得分:6)

C#

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

vb.net

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

vb.net(使用VB6样式函数)

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

答案 3 :(得分:1)

这是我在程序中使用的(VB.NET):

Dim myStr As String = "hello world"
myStr = TrimStr(myStr, " world")

用法:


at least 340.00 is required for CUDA 6.5
at least 331.00 is required for CUDA 6.0
at least 319.00 is required for CUDA 5.5

这是我的第一个答案。希望它可以帮助某人。如果你不喜欢这个答案,请随意下载。