@ Andy
you should be using the Stringbuilder for that kind of stuff,
here a small sample
the debug outputCode:Option Strict On Public Class Form2 Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click Debug.Print(myStringLenght(TextBox1.Text, 18)) End Sub Private Sub Form2_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load 'TextBox1.Text = "JOHNSONS BABY COTTON BUDS 100PK" TextBox1.Text = "Astonisch Antibacteriel Surface Cleaner Spray-750ml" End Sub Function myStringLenght(ByVal Text As String, ByVal nLenght As Integer) As String Dim sb As New System.Text.StringBuilder Dim xLenght As Integer = nLenght For Each xWord As String In Text.Split({" "c}, StringSplitOptions.None) If xWord.Length < xLenght Then sb.AppendFormat(xWord & " ") xLenght -= xWord.Length - 1 ElseIf xWord.Length = xLenght Then sb.AppendFormat(xWord & vbCrLf) xLenght = nLenght Else sb.AppendFormat(vbCrLf & xWord & " ") xLenght = nLenght - xWord.Length - 1 End If Next Return sb.ToString End Function End Class
play a bit with it, and set the lenght from 18 to ....Code:Astonisch Antibacteriel Surface Cleaner Spray-750ml




Reply With Quote
