蝸牛的JAVA外殼

          ┎Running Snail┒ ┖ -------------- ┚

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            13 Posts :: 0 Stories :: 10 Comments :: 0 Trackbacks

          #

          1. 統計文本行數:wc -l filename
          2. 修改文件名稱:mv srcfilename tofilename
          posted @ 2007-04-22 12:21 會跑的蝸牛 閱讀(530) | 評論 (3)編輯 收藏

          定義:保證在Java程序中,一個Class只有一個實例存在。

          第一種實例:
           1public class Singleton {
           2
           3  private Singleton(){}
           4
           5  private static Singleton instance = new Singleton();
           6
           7  public static Singleton getInstance() {
           8    return instance;   
           9   }
           
          10}

          11 
          12


          第二種實例:

           1public class Singleton 
           2
           3  private static Singleton instance = null;
           4
           5  public static synchronized Singleton getInstance() {
           6      if (instance==null)
           7        instance=new Singleton();
           8      return instance;   
           9    }
           
          10
          11}

          12
          posted @ 2007-04-22 01:45 會跑的蝸牛 閱讀(234) | 評論 (0)編輯 收藏

           1<script>
           2String.prototype.truncate = function(bytes) {
           3
           4    str = this;
           5    showstr = "";
           6
           7    flag = false;
           8
           9    strleg = string_get_ascii_leg(str);
          10
          11    if (strleg > bytes)
          12    {
          13        for (i=0,j=0;i<bytes;i++,j++)
          14        {
          15            showstr = showstr.concat(str.charAt(j));
          16            if (!(str.charCodeAt(i) < 255))//是否是英文字符
          17            {
          18                i++;
          19            }

          20        }

          21        showstr = showstr.concat("");
          22    }

          23    else
          24    {
          25        showstr = str;
          26    }

          27    return showstr;
          28}

          29function string_get_ascii_leg(indata)
          30{
          31    var i,strleg;
          32
          33    strleg = 0;
          34    for (i=0;i<indata.length;i++)
          35    {
          36        strleg++;
          37        if (indata.charCodeAt(i) > 255)
          38        {
          39            strleg++;
          40        }

          41    }

          42
          43    return strleg;
          44}

          45</script>

          Example:
          1<script>
          2var test = "我們在哪里";
          3alert(test.truncate(6));
          4</script>
          posted @ 2007-04-22 01:37 會跑的蝸牛 閱讀(1107) | 評論 (0)編輯 收藏

          僅列出標題
          共2頁: 上一頁 1 2 
          主站蜘蛛池模板: 澄城县| 尤溪县| 丹凤县| 康乐县| 九江县| 杭锦后旗| 太湖县| 平度市| 东明县| 湖州市| 天峨县| 林州市| 上栗县| 鄂伦春自治旗| 英超| 泾川县| 雷州市| 尚志市| 保靖县| 吉林省| 普定县| 北安市| 通江县| 河北省| 民县| 楚雄市| 五原县| 江都市| 仁化县| 昆明市| 万源市| 蒙自县| 盐边县| 元阳县| 广东省| 长丰县| 馆陶县| 临沧市| 滁州市| 富平县| 鄄城县|