PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 5.00 average.

Function to split long string into "sentences"

 
 
John
Guest
Posts: n/a
 
      8th May 2008
Hi

I have written a function to split a string into sub strings of a given
fixed max length. This is useful for example in breaking a long message into
multiple strings of up to 160 characters to be sent as individual SMS.

I am posting the function here in case its useful for someone.

Regards


'Function to split a long string into sentences of upto MaxLength size
Public Function Split(ByVal Expression As String, ByVal MaxLength As
Integer) As String()
Dim Separator As String = " "
Dim OutAr(0) As String
Dim j As Integer
Dim i As Integer

j = 0
While Expression <> ""
If Microsoft.VisualBasic.Len(Expression) <= MaxLength Then
ReDim Preserve OutAr(j)
OutAr(j) = Expression
Expression = ""
Else
i = InStrRev(Microsoft.VisualBasic.Left(Expression,
MaxLength + 1), Separator)
If i = 0 Then
ReDim Preserve OutAr(j)
OutAr(j) = Microsoft.VisualBasic.Left(Expression,
MaxLength)
Expression = Microsoft.VisualBasic.Right(Expression,
Len(Expression) - MaxLength)
j = j + 1
Else
ReDim Preserve OutAr(j)
OutAr(j) = Microsoft.VisualBasic.Left(Expression, i - 1)
Expression = Microsoft.VisualBasic.Right(Expression,
Len(Expression) - i)
j = j + 1
End If
End If
End While

Split = OutAr
End Function


 
Reply With Quote
 
 
 
 
New Member
Join Date: Jun 2010
Posts: 3
 
      1st Aug 2012
Many thanks - very useful

Roy
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Long Long Long Nested If Function sed Microsoft Excel Misc 4 9th Dec 2009 07:44 PM
Can I split a string or use the split function in design view? Michelle Microsoft Access Queries 3 31st May 2009 09:23 PM
save the whole string into a field and use a string array to split =?Utf-8?B?Q3VyaWU=?= Microsoft Access VBA Modules 4 20th Aug 2005 01:33 PM
String.Split(), Regex.Split() - empty String Rico Microsoft C# .NET 3 27th Jun 2005 04:26 PM
String.Split versus Strings.Split kurt sune Microsoft VB .NET 5 30th Mar 2005 04:53 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:10 PM.