473,395 Members | 1,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

ASP Trim Function?

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

Jul 22 '05 #1
9 2600
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!
Jul 22 '05 #2
"Johnboy" wrote in message
news:11**********************@g49g2000cwa.googlegr 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
Jul 22 '05 #3

"Johnboy" <jh******@trekkin.com> wrote in message
news:11**********************@g49g2000cwa.googlegr 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

Jul 22 '05 #4
"Johnboy" <jh******@trekkin.com> wrote in message
news:11**********************@g49g2000cwa.googlegr 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>")
%>
Jul 22 '05 #5
This will fail if the string has less than 7 spaces available.

'dlbjr
'Pleading sagacious indoctrination!
Jul 22 '05 #6
"dlbjr" <oo**@iforgot.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
This will fail if the string has less than 7 spaces available.

'dlbjr
'Pleading sagacious indoctrination!

Why not test it and see?
Jul 22 '05 #7
I did!. It will not append the needed anchor, because the position is not found..

'dlbjr
'Pleading sagacious indoctrination!
Jul 22 '05 #8
"dlbjr" <oo**@iforgot.com> wrote in message
news:eh*************@TK2MSFTNGP15.phx.gbl...
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.
Jul 22 '05 #9
"Chris Hohmann" wrote in message
news:Oa**************@TK2MSFTNGP12.phx.gbl...
: "dlbjr" <oo**@iforgot.com> wrote in message
: news:eh*************@TK2MSFTNGP15.phx.gbl...
: >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
Jul 22 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Simon | last post by:
Hi, I have written a function to trim char *, but I have been told that my way could be dangerous and that I should use memmove(...) instead. but I am not sure why my code could be 'dangerous'...
12
by: Robert Mark Bram | last post by:
Hi All, I am using the following trim function: function trim (str) { return str.replace(/^\s*/g, '').replace(/\s*$/g, ''); } The problem is that this doesn't trim instances of the...
3
by: Andy B | last post by:
I've tried using Trim or RTrim to strip trailing space characters from my data. When I check on the transformed data space characters are still there. We have an address table containing two...
11
by: Darren Anderson | last post by:
I have a function that I've tried using in an if then statement and I've found that no matter how much reworking I do with the code, the expected result is incorrect. the code: If Not...
7
by: Sascha Herpers | last post by:
Hi, what is the difference between the trim function and the trim String-member? As far as I see it, both return the trimmed string and leave the original string unaltered. Is any of the two...
22
by: Terry Olsen | last post by:
I have an app that makes decisions based on string content. I need to make sure that a string does not contain only spaces or newlines. I am using the syntax 'Trim(String)" and it works fine. I...
31
by: rkk | last post by:
Hi, I've written a small trim function to trim away the whitespaces in a given string. It works well with solaris forte cc compiler, but on mingw/cygwin gcc it isn't. Here is the code: char...
12
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I trim whitespace - LTRIM/RTRIM/TRIM?...
5
by: Marjeta | last post by:
I'm trying to very that the user actually entered something in the form, and not just spaces. I guess the problem is in the first line of isBlank() function. I've tried the following:...
8
by: Keith Thompson | last post by:
Kevin Smith <no@spam.comwrites: You posted this to microsoft.public.dotnet.languages.csharp, where I presume it's topical. Why on Earth did you redirect followups to comp.lang.c? Anyone...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.