蝸牛的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 會跑的蝸牛 閱讀(534) | 評論 (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 會跑的蝸牛 閱讀(239) | 評論 (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 會跑的蝸牛 閱讀(1112) | 評論 (0)編輯 收藏

          僅列出標題
          共2頁: 上一頁 1 2 
          主站蜘蛛池模板: 蓝山县| 南丹县| 广平县| 托里县| 兴城市| 易门县| 岑巩县| 西丰县| 章丘市| 昭觉县| 仪陇县| 祁阳县| 奉新县| 临沂市| 淮滨县| 定远县| 永和县| 和田市| 宁南县| 中山市| 丽水市| 威信县| 嘉义县| 宜宾县| 寿阳县| 盐边县| 晋江市| 辛集市| 长宁县| 广西| 东平县| 景洪市| 洛宁县| 甘泉县| 河北省| 集贤县| 富锦市| 乐平市| 余江县| 建始县| 泉州市|