Public Function StringTruncate(ByVal str As String, char As String, maxLength As Long) As String
If Len(str) > maxLength + Len(char) Then
str = Left(str, maxLength + Len(char))
End If
If Right(str, Len(char)) = char Then
StringTruncate = Left(str, Len(str) - Len(char))
ElseIf Len(str) < Len(char) Then
StringTruncate = ""
Else
StringTruncate = StringTruncate(Left(str, Len(str) - 1), char, maxLength)
End If
End Function
This any use?
Code:Public Function StringTruncate(ByVal str As String, char As String, maxLength As Long) As String If Len(str) > maxLength + Len(char) Then str = Left(str, maxLength + Len(char)) End If If Right(str, Len(char)) = char Then StringTruncate = Left(str, Len(str) - Len(char)) ElseIf Len(str) < Len(char) Then StringTruncate = "" Else StringTruncate = StringTruncate(Left(str, Len(str) - 1), char, maxLength) End If End Function
Private Sub Command1_Click()
'create a variable called mystr
mystr = Text1.Text
'split the text
textsplit = Split(mystr, ",")
'numcom is popoluated with UBound, giving us the total number of pieces of info in the string
numcom = UBound(textsplit)
'replace 8 with 8000, if our string is larger than 8000 characters then take one comma off
If Len(mystr) > 8 Then
numcom = numcom - 1
End If
x = 1
txtvar = 1
'do until x = to the number of commas
Do Until x = numcom
'keep adding to our strvar variable until we hit a comma
strvar = strvar & Mid(mystr, txtvar, 1)
'increase the amount in the string by 1
txtvar = txtvar + 1
'if we've ended on a comma, add one onto our count
If Right(strvar, 1) = "," Then
x = x + 1
End If
Loop
'populate text2 with our new string
Text2.Text = strvar
End Sub
nice one managed to get both version working although nikebee yours is in .net not VB6
thanks a lot guys top work