Delphi function to convert Result of WrapText to TStringList

I use this function to insert carriage returns on a string so it is nicely formatted for emailing:

  m := WrapText(m, #13#10, ['.',' ',#9,'-'], 60);

The problem is my email client has a 1023 character limit when processing strings. So if the original length of m is greater than 1023, it gets truncated (Note: the email client probably has events to handle this situation, but I think an easier approach is to just feed it strings less than the limit).

I am looking for a "WrapTextToStringList" function like this:

var
  mStringList: TStringList;
begin
  mStringList := WrapTextToStringList(m, #13#10, ['.',' ',#9,'-'], 60);

So say I passed this a 220 character body of an email message. The results would be a string list with approximately 4 entries.

I think this just boils down to creating a function which parses a string at #13#10 into a string list.

Anyone got one?

Answers


TStringList already has a built-in method to parse a string at #13#10 into a string list.

MyStringList := TStringList.Create;
MyStringList.Text := MyString;

This will populate the list by parsing the string and creating a new entry in the list whenever it finds a return.


Need Your Help

Howto serialize and deserialize CDI Bean to file

java serialization cdi weld

I'm building a JSF application. The JSF application contains some CDI beans, which hold the session data. I want to save this session data to a file and load it at a later time.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.