473,382 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Function to split long string into "sentences"

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
Jun 27 '08 #1
0 1589

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

68
by: Marco Bubke | last post by:
Hi I have read some mail on the dev mailing list about PEP 318 and find the new Syntax really ugly. def foo(x, y): pass I call this foo(1, 2), this isn't really intuitive to me! Also I...
28
by: Alf P. Steinbach | last post by:
A few days ago I posted an "Hello, world!" tutorial, discussed in <url: http://groups.google.no/groups?threadm=41ba4c0a.76869078@news.individual.net>. As I wrote then: <quote> because there...
46
by: TTroy | last post by:
Hi, I'm just wondering why people/books/experts say "the function returns a pointer to.." or "we have to send scanf a pointer to.." instead of "the function returns the address of.." or "we have...
175
by: Ken Brady | last post by:
I'm on a team building some class libraries to be used by many other projects. Some members of our team insist that "All public methods should be virtual" just in case "anything needs to be...
23
by: Rogers | last post by:
I want to compare strings of numbers that have a circular boundary condition. This means that the string is arranged in a loop without an end-of-string. The comparaison of two strings now...
35
by: pinkfloydhomer | last post by:
How do I check if a string contains (can be converted to) an int? I want to do one thing if I am parsing and integer, and another if not. /David
37
by: jht5945 | last post by:
For example I wrote a function: function Func() { // do something } we can call it like: var obj = new Func(); // call it as a constructor or var result = Func(); // call it as...
9
by: xorax | last post by:
Hi, I am a new member of this forum but I'm french so... make easy sentences which I can understand please :) I have a javascript code in a string variable : var jscode = "var test = 'test...
10
by: 66650755 | last post by:
First,thanks for all who have answered my last question. if char string="12345"; how could I convert the string(that is "3") to an int by using atoi? I only want to convert...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.