Help with function to split strings

# Thread: Help with function to split strings

1. Senior Member
Join Date
Dec 1969
Posts
188

## Help with function to split strings

I need help to create a function which will split a string on a given length of the string and put the result in an array or a string. Please see below:<BR>-----------------------------------------------------<BR>str = "This is an example of the string i want to change..."<BR>cutString 20, str &#039;call function<BR><BR>the cutString function should then convert the string to the following:<BR><BR>&#039; Split string at every 20 chars...<BR>string = "This is an example " & "<BR>"<BR>string = string & "of the string i wan" & "<BR>"<BR>string = string & "t to change..." & "<BR>"<BR>-----------------------------------------------------<BR>... or into an array. So as you can see i want a "line breaker" function. If anyone has any better approaches on doing such a function please let me know...<BR><BR>Cheers<BR>Anders

2. Eddie Campbell Guest

## RE: Help with function to split strings

This should do the job. If you need to ensure that the line only breaks on a space between words, you will need to do a bit of tweaking<BR><BR>&#060;%<BR>Str = "This is an example of the string I want to change..."<BR>Dim RowCount<BR>ReDim MyArray(Cint(Len(str)/20))<BR>RowCount = 0<BR>Do While Len(Str) &#062; 0<BR> MyArray(RowCount) = Left(Str,20)<BR> If Len(Str) &#062; 20 then<BR> Str=Right(Str,Len(Str)-20)<BR> Else<BR> Str = ""<BR> End If<BR> RowCount = RowCount + 1<BR>Loop<BR>For I = 0 to Ubound(MyArray) -1<BR> Response.write "Array Element " & I & ": &#060;b&#062;" & MyArray(I) & "&#060;/b&#062;<BR>"<BR>Next<BR>%&#062;

3. Senior Member
Join Date
Dec 1969
Posts
19,082

## RE: Help with function to split strings

I&#039;ve got one in JScript which splits at the nearest word boundary to a gven amount - let me know<BR><BR>j

4. Senior Member
Join Date
Dec 1969
Posts
188

## RE: Help with function to split strings

Thanks!<BR><BR>..a

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•