Monday, March 12, 2012

Getting Paragraph Count

Hi,
I need to get a paragraph count of text
1. Pasted into a SQLServer VARCHAR field from Word, and also
2. Entered directly into a SQLServer VARCHAR field entered via an Access ADP
textbox
I tried using
CHARINDEX (ColumnName, CHAR(10),1)
CHARINDEX (ColumnName, CHAR(13) ,1)
CHARINDEX (ColumnName, ' ', 1)
to find the first instance of a blank line, but all returned zero.
Is there a way to count the paragraphs, i.e. blank lines between paragraphs?
Once I know how to find the blank lines, I can loop through text to find all
occurences.
Thanks.
AlanNEVER MIIND!
I had expression order reversed!
Alan
"Alan Z. Scharf" <ascharf@.grapevines.com> wrote in message
news:ulLxGNQUGHA.5172@.TK2MSFTNGP12.phx.gbl...
> Hi,
> I need to get a paragraph count of text
> 1. Pasted into a SQLServer VARCHAR field from Word, and also
> 2. Entered directly into a SQLServer VARCHAR field entered via an Access
ADP
> textbox
> I tried using
> CHARINDEX (ColumnName, CHAR(10),1)
> CHARINDEX (ColumnName, CHAR(13) ,1)
> CHARINDEX (ColumnName, ' ', 1)
> to find the first instance of a blank line, but all returned zero.
> Is there a way to count the paragraphs, i.e. blank lines between
paragraphs?
> Once I know how to find the blank lines, I can loop through text to find
all
> occurences.
> Thanks.
> Alan
>|||You could try this sort of thing. If you remove all the paragraph dividers
from a piece of text, you can then compare the lengths of the original strin
g
with the new one, to see how much text you removed. Divide it by the length
of the paragraph divider, and you have how many there were. Add one because
you're counting the paragraph-splits, not the paragraphs themselves.
Like this (but obviously you wouldn't have to use variables, you could just
use your column names directly):
declare @.text varchar(8000)
set @.text = 'Here is some text.
Here is a second paragraph.
Here is a third.'
declare @.paragraphdivider char(4)
set @.paragraphdivider = char(13)+char(10)+char(13)+char(10)
declare @.paragraphs int
select @.paragraphs = (len(@.text) - len(replace(@.text,@.paragraphdivider,''))
)
/ len(@.paragraphdivider) + 1
select @.paragraphs
"Alan Z. Scharf" wrote:

> NEVER MIIND!
> I had expression order reversed!
> Alan
>
> "Alan Z. Scharf" <ascharf@.grapevines.com> wrote in message
> news:ulLxGNQUGHA.5172@.TK2MSFTNGP12.phx.gbl...
> ADP
> paragraphs?
> all
>
>

No comments:

Post a Comment