splitting a master string in smaller sub-strings
Posted on 1999-01-22
I want to split this masterstring:
masterstring:= 'This is a sample string which should be examined by the experts in order to demonstrate which result I want
if I split a string.';
This string has a size of exactly 128 characters.
How can I split this big masterstring to 3 substrings with the following restriction:
a) None of the resulting sub-strings must exceed an individual lenghth of 50 characters.
b) The masterstring must not be split within a word. So if you find a non-blank at positions
50 or 100 you must split at the first blank preceeding this word.
c) I know that my masterstring never exceeds a limit of 150 characters, so 3 resultstrings will be enough
in any case to display the resulting substrings in editboxes.
For example: In my masterstring position 50 is the "y" within "by". In this case - as you must
not split the "by" - we need a split at the blank between"examined" and "by".
If the splitting procedure works correctly, you should get this result in the end:
edit1.text:='This is a sample string which should be examined';
edit2.text:='by the experts in order to demonstrate which';
edit3.text:='result I want if I split a string.';
How would you solve this splitting-problem ?
With kind regards