Software Development Network>> Visual Basic>> Trimming a string
How about a function such as this which will return the string to the left of a specific character. So in your case you would call Dim StrResult as string StrResult = StripAtChar("333-000_004.txt", "_")And it would return "333-000" only. This way it is not specific to length of strings or positions but to delimiting characters.Hope that helps....
Private Function StripAtChar(ByVal x As String, ByVal Stripchar As Char) As String Try Dim pos As Integer pos = InStr(x, Stripchar)
If pos > 0 Then Return x.Substring(0, pos - 1) End If Catch ex As Exception
End Try
End Function
Private
TrimAtChar = Instring.Substring(0, Instring.IndexOf(Char1))
Trimming a string
optyler
How about a function such as this which will return the string to the left of a specific character. So in your case you would call
Dim StrResult as string
StrResult = StripAtChar("333-000_004.txt", "_")
And it would return "333-000" only. This way it is not specific to length of strings or positions but to delimiting characters.
Hope that helps....
Private Function StripAtChar(ByVal x As String, ByVal Stripchar As Char) As String
Try
Dim pos As Integer
pos = InStr(x, Stripchar)
If pos > 0 Then
Return x.Substring(0, pos - 1)
End If
Catch ex As Exception
End Try
End Function
Paul200607
So I think your code should look something like
NewString = OriginalString.remove(9, 4)
But if you have trouble with the characters being selected just try playing around with those numbers.
Madcoder
Private
Function TrimAtChar(ByVal Instring As String, ByVal Char1 As char) As String On Error Resume NextTrimAtChar = Instring.Substring(0, Instring.IndexOf(Char1))
End FunctionI just love the character extentions. I can't help it!
Tarek Ahmed Ismail
Thanks!!!!