Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > ASP Trim Function?

Reply
Thread Tools

ASP Trim Function?

 
 
Johnboy
Guest
Posts: n/a
 
      05-12-2005
Hi,
I'm creating a website that will have a page that lists current news
items. The news items will be stored in a SQL Server database and will
have basically two fields, the date and the news blurb . . . On the
main page of the site, I want to have a box that shows "Current News"
and only pulls the first 7 or so words from the news blurb followed by
a ... [more] where [more] is a link to the current news page.

For example, the database entry may be something like this:

5/12/05
Chicken Little reports sky is falling. Earlier today Mr. Little was
struck in the head by an unidentified object and immediately announced
the sky was falling.

So on the main page of the of the site it would say:

Current News:
5/12/05 Chicken Little reports sky is falling. Earlier ... [more]

Is there some sort of Trim function in ASP that I could use to count
the number of spaces in an article and if Less than 7 print the whole
thing, or if more than 7 trim all characters after the 7th space?

Any info would be greatly appreciated.

Thanks!
John

 
Reply With Quote
 
 
 
 
dlbjr
Guest
Posts: n/a
 
      05-13-2005
Dim ar2(6)
'Place text into an array
ar1 = Split(strText," ")
intMax = UBound(ar1)
If intMax > 6 Then
intMax = 6
End If
For i = 0 To intMax
ar2(i) = ar1(i)
Next
strNewString = Join(ar2," ") & "... [more] "

'dlbjr
'Pleading sagacious indoctrination!


 
Reply With Quote
 
 
 
 
Roland Hall
Guest
Posts: n/a
 
      05-13-2005
"Johnboy" wrote in message
news:(E-Mail Removed) oups.com...
: I'm creating a website that will have a page that lists current news
: items. The news items will be stored in a SQL Server database and will
: have basically two fields, the date and the news blurb . . . On the
: main page of the site, I want to have a box that shows "Current News"
: and only pulls the first 7 or so words from the news blurb followed by
: a ... [more] where [more] is a link to the current news page.
:
: For example, the database entry may be something like this:
:
: 5/12/05
: Chicken Little reports sky is falling. Earlier today Mr. Little was
: struck in the head by an unidentified object and immediately announced
: the sky was falling.
:
: So on the main page of the of the site it would say:
:
: Current News:
: 5/12/05 Chicken Little reports sky is falling. Earlier ... [more]
:
: Is there some sort of Trim function in ASP that I could use to count
: the number of spaces in an article and if Less than 7 print the whole
: thing, or if more than 7 trim all characters after the 7th space?
:
: Any info would be greatly appreciated.

My little version... (the last line is pretty long)

<%@ Language=VBScript %>
<%
Option Explicit
Response.Buffer = True

function getPos(d, a)
dim char, count, pos
char = chr(32) : count = 0
pos = instr(1, article, char)
do until count = 7
count = count + 1
if pos = 0 then
exit do
else
pos = instr(pos + 1, article, char)
end if
loop
getPos = pos
end function

dim articleDate, article, p, preview, fullview
articleDate = #5/12/05#
article = "Chicken Little reports sky is falling. Earlier today Mr. Little
was struck in the head by an unidentified object and immediately announced
the sky was falling."

p = getPos(articleDate, article)

if p = 0 then
Response.Write articleDate & " " & article
else
preview = left(article,p)
fullview = mid(article,p)
Response.Write articleDate & " " & left(article,p) & "<span
id=""ellipse""> ... </span><span id=""article"" style=""cursor: pointer;
color: blue"" onmouseover=""this.style.backgroundColor='#eef'""
onmouseout=""this.style.backgroundColor='#fff'""
onclick=""document.getElementById('ellipse').inner HTML='';
this.style.cursor='text'; onmouseover=''; this.style.color='#000';
this.innerHTML='" & fullview & "'"">[more]</span>"
end if
%>

http://kiddanger.com/lab/morearticle.asp

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp


 
Reply With Quote
 
Agoston Bejo
Guest
Posts: n/a
 
      05-13-2005

"Johnboy" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> Hi,
> I'm creating a website that will have a page that lists current news
> items. The news items will be stored in a SQL Server database and will
> have basically two fields, the date and the news blurb . . . On the
> main page of the site, I want to have a box that shows "Current News"
> and only pulls the first 7 or so words from the news blurb followed by
> a ... [more] where [more] is a link to the current news page.
>
> For example, the database entry may be something like this:
>
> 5/12/05
> Chicken Little reports sky is falling. Earlier today Mr. Little was
> struck in the head by an unidentified object and immediately announced
> the sky was falling.
>
> So on the main page of the of the site it would say:
>
> Current News:
> 5/12/05 Chicken Little reports sky is falling. Earlier ... [more]
>
> Is there some sort of Trim function in ASP that I could use to count
> the number of spaces in an article and if Less than 7 print the whole
> thing, or if more than 7 trim all characters after the 7th space?


Dim words, nWords
words = Split(myText)
nWords = UBound(words)
ReDim words(7)
Response.Write Join(words)
If nWords >= 7 Then
Response.Write "... [more]"
End If

Although if you would like to consider multiple spaces or whitespaces as one
space, you're going to have to convert the original string so that it
contains only one space between each word.

>
> Any info would be greatly appreciated.
>
> Thanks!
> John
>



 
Reply With Quote
 
Chris Hohmann
Guest
Posts: n/a
 
      05-15-2005
"Johnboy" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> Hi,
> I'm creating a website that will have a page that lists current news
> items. The news items will be stored in a SQL Server database and will
> have basically two fields, the date and the news blurb . . . On the
> main page of the site, I want to have a box that shows "Current News"
> and only pulls the first 7 or so words from the news blurb followed by
> a ... [more] where [more] is a link to the current news page.
>
> For example, the database entry may be something like this:
>
> 5/12/05
> Chicken Little reports sky is falling. Earlier today Mr. Little was
> struck in the head by an unidentified object and immediately announced
> the sky was falling.
>
> So on the main page of the of the site it would say:
>
> Current News:
> 5/12/05 Chicken Little reports sky is falling. Earlier ... [more]
>
> Is there some sort of Trim function in ASP that I could use to count
> the number of spaces in an article and if Less than 7 print the whole
> thing, or if more than 7 trim all characters after the 7th space?
>
> Any info would be greatly appreciated.
>
> Thanks!
> John
>

<%
Dim s, re
s = "Chicken Little reports sky is falling. Earlier today Mr. Little was
struck in the head by an unidentified object and immediately announced the
sky was falling."
Set re = New RegExp
re.Pattern = "((\S+\s+){7})(.+)"
Response.Write re.Replace(s,"$1...<a href=""#"">[more]</a>")
%>


 
Reply With Quote
 
dlbjr
Guest
Posts: n/a
 
      05-15-2005
This will fail if the string has less than 7 spaces available.

'dlbjr
'Pleading sagacious indoctrination!


 
Reply With Quote
 
Chris Hohmann
Guest
Posts: n/a
 
      05-15-2005
"dlbjr" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> This will fail if the string has less than 7 spaces available.
>
> 'dlbjr
> 'Pleading sagacious indoctrination!
>
>

Why not test it and see?


 
Reply With Quote
 
dlbjr
Guest
Posts: n/a
 
      05-16-2005
I did!. It will not append the needed anchor, because the position is not found..

'dlbjr
'Pleading sagacious indoctrination!


 
Reply With Quote
 
Chris Hohmann
Guest
Posts: n/a
 
      05-16-2005
"dlbjr" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I did!. It will not append the needed anchor, because the position is not
>found..
>
> 'dlbjr
> 'Pleading sagacious indoctrination!
>
>

Why would you need an anchor if the entirety of the article was listed on
the page? I took the OP to mean that if the entire article was seven (7)
words or less, print it. Else, print the first seven word and a more link.
That's what I got out of the last paragraph in the original post. If he/she
wants a more link for every blurb, regardless of length, he/she can do this:

<%
Dim s1, s2, re
s1 = "Chicken Little reports sky is falling. Earlier today Mr. Little was
struck in the head by an unidentified object and immediately announced the
sky was falling."
s2 = "Very short article."
Set re = New RegExp
re.Pattern = "((\S+\s+){7})(.+)"
Response.Write re.Replace(s1,"$1") & "...<a href=""#"">[more]</a><br>"
Response.Write re.Replace(s2,"$1") & "...<a href=""#"">[more]</a><br>"
%>

In either case, I'm not sure the word "fail" was appropriate here. We simply
had differing interpretations of the requirements.


 
Reply With Quote
 
Roland Hall
Guest
Posts: n/a
 
      05-16-2005
"Chris Hohmann" wrote in message
news:(E-Mail Removed)...
: "dlbjr" <(E-Mail Removed)> wrote in message
: news:(E-Mail Removed)...
: >I did!. It will not append the needed anchor, because the position is not
: >found..
: >
: > 'dlbjr
: > 'Pleading sagacious indoctrination!
: >
: >
: Why would you need an anchor if the entirety of the article was listed on
: the page? I took the OP to mean that if the entire article was seven (7)
: words or less, print it. Else, print the first seven word and a more link.
: That's what I got out of the last paragraph in the original post. If
he/she
: wants a more link for every blurb, regardless of length, he/she can do
this:
:
: <%
: Dim s1, s2, re
: s1 = "Chicken Little reports sky is falling. Earlier today Mr. Little was
: struck in the head by an unidentified object and immediately announced the
: sky was falling."
: s2 = "Very short article."
: Set re = New RegExp
: re.Pattern = "((\S+\s+){7})(.+)"
: Response.Write re.Replace(s1,"$1") & "...<a href=""#"">[more]</a><br>"
: Response.Write re.Replace(s2,"$1") & "...<a href=""#"">[more]</a><br>"
: %>
:
: In either case, I'm not sure the word "fail" was appropriate here. We
simply
: had differing interpretations of the requirements.

Nice Chris. A little modification so it just expands the text...

Dim s, re
s = "Chicken Little reports sky is falling. Earlier today Mr. Little was
struck in the head by an unidentified object and immediately announced the
sky was falling."
Set re = New RegExp
re.Pattern = "((\S+\s+){7})(.+)"
Response.Write re.Replace(s,"$1<span onclick=""this.innerHTML='$3'"">
....[more]</span>")

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FAQ Topic - How do I trim whitespace - LTRIM/RTRIM/TRIM? FAQ server Javascript 2 04-24-2007 01:59 AM
FAQ Topic - How do I trim whitespace - LTRIM/RTRIM/TRIM? FAQ server Javascript 26 02-26-2007 05:06 PM
FAQ Topic - How do I trim whitespace - LTRIM/RTRIM/TRIM? FAQ server Javascript 6 12-25-2006 08:47 PM
FAQ Topic - How do I trim whitespace - LTRIM/RTRIM/TRIM? FAQ server Javascript 0 10-25-2006 11:00 PM
FAQ Topic - How do I trim whitespace - LTRIM/RTRIM/TRIM? FAQ server Javascript 0 08-28-2006 11:00 PM



Advertisments