# \[Flash\] 为句子添加省略

**URL:** <https://perak.org/t/flash-%E4%B8%BA%E5%8F%A5%E5%AD%90%E6%B7%BB%E5%8A%A0%E7%9C%81%E7%95%A5/51741>\
**Category:** 程序设计\
**Created:** [2006 年4 月 29 日 10:35 UTC](https://perak.org/t/flash-%E4%B8%BA%E5%8F%A5%E5%AD%90%E6%B7%BB%E5%8A%A0%E7%9C%81%E7%95%A5/51741 "2006-04-29T10:35:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

作者： ![super-tomato](https://perak.org/letter_avatar_proxy/v4/letter/s/a587f6/32.png) [@super-tomato](https://perak.org/u/super-tomato)\
发布日期： [2006 年4 月 29 日 10:35 UTC](https://perak.org/t/flash-%E4%B8%BA%E5%8F%A5%E5%AD%90%E6%B7%BB%E5%8A%A0%E7%9C%81%E7%95%A5/51741/1 "2006-04-29T10:35:23Z")

</div>

作者：Super-Tomato  
原文：[http://www2.flash8.net/teach/3446.htm](http://www2.flash8.net/teach/3446.htm)

String.prototype.reduce = function(num, str) {  
if (this.length\<num) return this; //判断句子长度是否超过限定，未超过就返回  
var myStr = this.substr(0, num); //取得句子长度内容  
var t = myStr.split(" “); //把每段文字以空格分开  
t.pop(); //把最后一段删除  
var lastStr = t[t.length-1];  
if(lastStr.substr(-1,1).charCodeAt() \< 65) t[t.length-1] = lastStr.substr(0, lastStr.length-1); //判断最后的一个字是否为文字  
return t.join(” ")+str; //把每段结合起来最后再加上省略符号  
};  
var str = “Hello, i’m Super-Tomato. Nice to meet you ^\_^”;  
trace(str.reduce(25, “…”)); //第一参数为限制的长度，第二参数为省略文字

//输出为 Hello, i’m Super-Tomato…

---

<div class="post-metadata">

作者： ![yee5008331](https://perak.org/letter_avatar_proxy/v4/letter/y/85e7bf/32.png) [@yee5008331](https://perak.org/u/yee5008331)\
发布日期： [2006 年7 月 14 日 07:15 UTC](https://perak.org/t/flash-%E4%B8%BA%E5%8F%A5%E5%AD%90%E6%B7%BB%E5%8A%A0%E7%9C%81%E7%95%A5/51741/2 "2006-07-14T07:15:28Z")

</div>

谢谢分享哦 Y^^
