VB6 string trunk

Soldato
Joined
18 Oct 2002
Posts
4,925
got a string like so


12345, 12345, 12345, 12345, 12345

I need to ensure it doesn't grow longer than 8000 characters so I need to tryim it to the nearest ',' on the right under 8000 characters.

Any ideas ?

Oh yes and using VB6
 
right not sure if I was totaly clear.

I can trim spaces, and cut down the string to x number of characters etc. My problem is I need it to be cut to a specific character a ',' before the cut off point i.e.

This is the string, but in reality it can be any length as its generated dynamically.

12345, 12345, 12345, 12345, 12345

Now say the cut off is 24 characters, is would make the string

12345, 12345, 12345, 123

But then I need to cut this again so the string is

12345, 12345, 12345,

is there a function in vb6 that will allow me to locate the first instance of a certain character i.e. a ',' which is closest to the right had side of the string ??

The only way I can think to do it would be to cut the string then get the length of the cut string and walk though it a character at a time from the right and remove everything until I encounter a ','.
 
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

Umm looking at the code I think it might, just realy doing what I mentioned and triming to to length needed then walking 1 char each time from the right till it finds a ','.

Will give it a bash when I get back in.

Thanks mate
 
nice one managed to get both version working although nikebee yours is in .net not VB6 :)

thanks a lot guys top work
 
Back
Top Bottom