Ok let me start explaining how I handle the string wrapping. Before that let me let me tell you the requirement.
-- Get the first word of the string without the space.
lc_word := substr(lc_data,1,instr(lc_data,' ')-1);
--get the length of the existing word on the current line with the current word.
ln_lgth := ln_lgth + NVL(length(lc_word),0);
--Add 1 for space when calculating the total length so.
ln_tot_lgth := ln_tot_lgth + NVL(length(lc_word),0)+1;
--if length of the existing word on the current line with the current word
--is more than 24 means then the line will break into two.
IF ln_lgth >= 24 THEN
ln_row := ln_row+1;
ln_lgth := ln_lgth+1;
exit when ln_tot_lgth >= ln_Act_lgth;
--get the balance remaining string apart from the current word.
lc_data := substr(lc_data,instr(lc_data,' ')+1);
I know as usual I had not formatted this post well But for your convenience I had attached the sample RTF and XML file here