Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Forcing Spaces in Text

Options
  • 20-01-2003 7:53pm
    #1
    Registered Users Posts: 604 ✭✭✭


    Hello,
    right im sure this has come up before but i couldnt seem to find it.
    Its about forcing text to wrap on long strings with no spaces e.g
    fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff

    What i want to be able to do is Search thru a string and find any words longer than X amount of characters and if there are any the force a space or else wrap them in some way so that i wont get horizontal scrollbars.
    Ive tried writing my own but i keep running into problems.
    The trick is its for a dynamic page so it has to be in an ASP script that will format the text and enter spaces where needed and then then output the text.
    anyone have any ideas or pointers, im using vbscript by the way.

    Thanks


Comments

  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    I've not tested this, but here you go:
    Function ForceWrap(sRaw)
    	Dim iMaxLength, iCounter
    	Dim Temp, i
    
    	iMaxLength = 30
    	iCounter = 1
    	For i = 1 To Len(sRaw)
    		Temp = Temp & Mid(sRaw, i, 1)
    		If Mid(sRaw, i, 1) = " " Then
    			iCounter = 1
    		ElseIf iCounter = iMaxLength Then
    			iCounter = 1
    			Temp = Temp & "<BR>" & vbCrLF
    		Else
    			iCounter = iCounter + 1
    		End If
    	Next
    
    	ForceWrap = Temp
    End Function
    


Advertisement