Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Triming a string? 1

Status
Not open for further replies.

snowboardr

Programmer
Feb 22, 2002
1,401
PH
What would be the best way to trim a string such as a news article so I could show "Start of article here..[more]"

I could use NewString = Left(MyArticle, 40) but that would cut off words etc...

Any ideas?

Jason
 
Search for the first few words using spaces.

var intro = new String();
var splits = MyArticle.split(" ");
var introWordLength=4;

for(var j=0;j<(introWordLength+1);j++){
intro += splits[j];
}


intro += &quot; <a href=&quot;nextpage.asp&quot;>more...</a>&quot;;

There is, no doubt, are more efficient solution - here the poor server has to read to whole article. Or you could have the first sentence - or whatever.
<bb/>
 
hmm I wonder If I can trim to space number such and such... so it doesnt have to split the whole article..
 
What id you used Left - but checked that the character you finish on is a space?

I've got a feeling the server has to load the whole thing anyway to operate on it.

If I was worried, and I was you, then I would probably make them XML files - this way you can have separate information for the title - link - date etc, then grab the content only when you want to write it in.

This way you can make an index quicker, without the server having to read what may be large amouonts of text.

You could alos just store a link to the file, if you don't want to rewrite all your articles.

<bb/>
 
Hi

For smooth, one line code try this:

Code:
intro=left(myarticle,inStr(40,myarticle,&quot; &quot;)-1) & &quot;...&quot;

Which will return the first 40 characters of the field up to the next space after that. Derren
[The only person in the world to like Word]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top