You are correct. My solution does not take into account that a tab can count as 1,2,3,4 or 5 characters depending on how close it is to the end of a line. Your solution works but assumes that it is okay to split words across two lines like this assuming column width of 8:
The quic k brown fox jump ed It also assumes that it is ok to begin a new line with spaces. Hopefully, that's what you want. Regards, Mike On Thu, Sep 25, 2008 at 10:26 AM, Vlad <[EMAIL PROTECTED]> wrote: > > Sorry Mike - I was having a hard day ;-) > > I may be wrong (seems common at the moment) but I don't think that > your example will work as if you had 10 lines, each with 79 characters > and a carriage return (Char(13) then your method would calculate that > you need ((10x79)+(10*80)/80)= 20, whereas it actually requires 10 > lines. > > I have actually finally managed to come up with a solution now though > - many thanks for all of your help. > > CREATE OR REPLACE FUNCTION CountLines > (TextString in varchar2, ColumnWidth in integer) > > RETURN NUMBER IS tmpVar NUMBER; > position integer; > linecount integer; > pos_var integer; > pos_curr integer; > > BEGIN > tmpVar := 0; > position := 1; > linecount := 1; > pos_curr := 0; > -- > WHILE position <= LENGTH(TextString) > LOOP > > pos_curr := pos_curr + 1; > pos_var := ASCII(SUBSTR(TextString, position, 1)) ; > > IF (pos_var = 9) > THEN > pos_curr := pos_curr + 5; > END IF ; > > IF (pos_var = 13 > --OR pos_var = 10 > OR pos_curr >= ColumnWidth) > THEN > > pos_curr := 0; > linecount := linecount + 1; > END IF; > > position := position + 1; > end loop; > > > > RETURN linecount; > EXCEPTION > WHEN NO_DATA_FOUND THEN > NULL; > WHEN OTHERS THEN > -- Consider logging the error and then re-raise > RAISE; > END CountLines; > > > > / > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Oracle PL/SQL" group. To post to this group, send email to Oracle-PLSQL@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/Oracle-PLSQL?hl=en -~----------~----~----~----~------~----~------~--~---