2008年5月21日星期三

郁闷

想自己写个web应用,东瞅瞅西看看,苦于没有思路....

正则表达式30分钟入门教程

需要写个正则替换字符,网上找来个入门教程,很实用

正则表达式30分钟入门教程

2008年5月20日星期二

oracle 随机取记录

select * from (select * from apply_info order by dbms_random.value) where rownum <= 3

2008年5月15日星期四

不用正则表达式替换字符串

public class Test {
/**
* Simplest in Java 1.5, using the replace method, which
* takes CharSequence objects.
*/
public static String replace15(
    String aInput, String aOldPattern, String aNewPattern
){
    return aInput.replace(aOldPattern, aNewPattern);
}

/**
* Not quite as simple in Java 1.4. The replaceAll method works,
* but requires more care, since it uses regular expressions, which
* may contain special characters.
*/
public static String replace14(
    String aInput, String aOldPattern, String aNewPattern
){

    /*
    * The replaceAll method is a bit dangerous to use.
    * The aOldPattern is converted into a regular expression.
    * Thus, if aOldPattern may contain characters which have
    * special meaning to regular expressions, then they must
    * be 'escaped' before being passed to replaceAll. It is
    * easy to forget to do this.
    *
    * In addition, aNewPattern treats '$' as special characters
    * as well: they refer to 'back references'.
    */
    return aInput.replaceAll(aOldPattern, aNewPattern);
    /*
    Here is an alternative implementation using Pattern and Matcher,
    which is preferred when the same pattern is used repeatedly
    final Pattern pattern = Pattern.compile( aOldPattern );
    final Matcher matcher = pattern.matcher( aInput );
    return matcher.replaceAll( aNewPattern );
    */
}

/**
* If Java 1.4 is unavailable, the following technique may be used.
*
* @param aInput is the original String which may contain substring aOldPattern
* @param aOldPattern is the non-empty substring which is to be replaced
* @param aNewPattern is the replacement for aOldPattern
*/
public static String replaceOld(
    final String aInput,
    final String aOldPattern,
    final String aNewPattern
){
     if ( aOldPattern.equals("") ) {
        throw new IllegalArgumentException("Old pattern must have content.");
     }

     final StringBuffer result = new StringBuffer();
     //startIdx and idxOld delimit various chunks of aInput; these
     //chunks always end where aOldPattern begins
     int startIdx = 0;
     int idxOld = 0;
     while ((idxOld = aInput.indexOf(aOldPattern, startIdx)) >= 0) {
       //grab a part of aInput which does not include aOldPattern
       result.append( aInput.substring(startIdx, idxOld) );
       //add aNewPattern to take place of aOldPattern
       result.append( aNewPattern );

       //reset the startIdx to just after the current match, to see
       //if there are any further matches
       startIdx = idxOld + aOldPattern.length();
     }
     //the final chunk will go to the end of aInput
     result.append( aInput.substring(startIdx) );
     return result.toString();
}

/** Example: update an ip address appearing in a link. */
public static void main (String[] aArguments) {
    String OLD_IP = "insert into LOAD_POLIINFO (IDCARD,POLISTAT,JOINDATE,LOADNO) values ('110102197906300508','13',to_date('null ','yyyy-mm-dd'),70990)";
log(replaceOld(OLD_IP,"to_date('null ','yyyy-mm-dd')","null"));
}
private static void log(String aMessage){
    System.out.println(aMessage);
}
}

参考自:http://www.javapractices.com/topic/TopicAction.do?Id=80

             http://biostar.blog.sohu.com/69732830.html

所谓专家 < 蛤蟆

养一群地震局“专家”,不如养一群蛤蟆

2008年5月9日星期五

从指定的数组中随机取n个

import java.util.*;

public class Test
{
public static void main(String[] agrs)
{
   int[] allIdList = new int[]{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
   int[] randomIdList = new Test().getRandomIdList(allIdList,10);
   for(int randomIdList_index = 0;randomIdList_index < randomIdList.length;randomIdList_index++){
    System.out.println(randomIdList[randomIdList_index]);
   }
}


/**
*
* @author liuzhaochun
* @explain:从指定的数组中随机取count个,返回这个数组
* @datetime:2008-5-9
* @return
* @return int [] 包含随机取的count个值的数组
*/
public int[] getRandomIdList(int[] allIdList,int count){
  
   int[] randomIdList = new int[count];
   int randomIdList_index = 0;
   for(int allIdList_index = allIdList.length - 1; randomIdList_index < count;allIdList_index--,randomIdList_index++){
    int temp_Index = (int)(Math.random() * allIdList_index);
    randomIdList[randomIdList_index] = allIdList[temp_Index];
    allIdList[temp_Index] = allIdList[allIdList_index];
   }
   return randomIdList;
}



}

2008年5月5日星期一

C#实现类似Excel自动填充单元格,后面的数字累加

class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(Next("abc123def345ghi"));
            Console.Read();

        }

        private static string Next(string s)
        {
            if (!isNumber(s.Substring(s.Length-1,1)))
                s = s + "0";
            MatchCollection coll = Regex.Matches(s, @"\d+");
            Match m = coll[coll.Count - 1];

            return s.Substring(0, m.Index) + NextNum(m.Value);
        }
        private static string NextNum(string s)
        {
            char[] cs = s.ToCharArray();
            for (int i = s.Length - 1; i >= 0; i--)
            {
                if (!NextChar(ref   cs[i])) break;
            }
          
            string re = new string(cs);
            if (Int32.Parse(re) == 0)
                re = "1" + re;
            return re;
        }
        private static bool NextChar(ref   char c)
        {
            string p = "01234567890123456789";
            int n = p.IndexOf(c);
            c = p[(n + 1) % 10 + 10 * (n / 10)];
            return (n == 9 || n == 19);
        }
        public static bool isNumber(string str)
        {
            Regex r = new Regex(@"^\d+(\.)?\d*$");
            if (r.IsMatch(str))
            {
                return true;
            }
            else
            {
                return false;
            }
        }

2008年4月30日星期三

五一了嘛 今儿咱民工高产

今儿咱民工真高产,劳动节了嘛,哈哈

真的希望像我那头猪一样啊,呵呵

睡吧,明天太阳会升起

不对,今天的太阳就要升起 呵呵

咯色的垃圾

咯色的垃圾就应该扔到无人烟的垃圾堆里,爱咋咋地去,省的惹别人一身臭

大家离我远点

怎样让自己平静 沉着

我遇到什么事不能解决就慌乱,心烦,跟他娘的女人来事儿似的,呵呵,据说是

更不用说,几件事压在头上了

能够坦然的,游刃有余的处理来自各方的琐事,可能就是比较高的人了吧,呵呵

想想,周末好像有成为黑色的趋势,听着老婆不时的唠叨妹妹的这啊那啊的,不知如何是好

小系统做了半年多还没结项,开始丧失在大大那的赏识

并且占用了我所有的业余时间,老婆都要跑了

而且老扯票撒谎的出去,心都虚了,每次要编个瞎话跟他娘的下地狱似的,痛苦

太嫩....

我真的变了吗

认识我的人大都说我变了

我难以判定,好像是变了,变怎么了?不知道,大多说我变垃圾了

开始时,看电视也好,电影也好,故事也好,两个人吵架,大都是因为互相不理解,有未言明的误会,吵啊吵的不可开交,甚至不可挽回,那时我就告诉自己,遇到这样的事一定要,立刻解释清楚,静下心来坦言,消除了误会,让对方理解了,也就好了。而现在,我很不想去解释,想的是如果言明了就没意思了,唉...可能也不能一概而论,可能也要分什么事情,可能也分什么关系的人,有默契的人可能就不用解释

人啊,郁闷而又闲闲的时候就容易胡思乱想。

开始有点讨厌这个公司了

发现如果某人惹你不高兴了,一段时间内,你看他哪都不顺眼,呵呵

北京人儿啊,都那么自信,自信的让人都只能隐形了

只知道让人干活的公司会是什么样?就像老一辈讲求无私奉献,为实现共产而努力奋斗,呵呵,我们得到什么了呢,老一辈还得到精神上的满足,我们连精神上的都没了,加班费都不好好给报了,我日啊,老子是喜欢钱地。

开始羡慕民工了,呵呵,

可咱翅膀还没长硬,忍着吧

学习 学习 学习

心情不好

心情不好时就抽烟,喝酒,可命的抽,昨晚浏览了个电影,韩国的,一帅哥爱喝酒抽烟,得了肝硬化,放下身边的工作,妈妈,女友,去疗养院了。呵呵,难道韩国有这样的规定?在我的世界不知道谁能做到去疗养院,能去医院看看,听医嘱,就是有条件的了。

从地铁出来都十一点了,看着外面一个个摆摊卖玉米的,等活儿的出租车司机,人活着比他妈狗都难。

今天公司聚餐,老总说她别看那么大岁数了,可比我们健康,让我们一定要注意身体,她每周都至少在健身房呆两个小时,呵呵,不是一个阶层的人啊,俺倒想去健身房,俺还没房住呢,咋整...

唉...内外兼忧啊

五一是什么节来着,我日啊

好像从开始上大学开始有五一放假这一说,大学时候的放假忘了都干啥了,只记得刚上大一的第一个十一是自己一个人在宿舍过的,大家都回家了。

毕业后的五一都该成我的受难日了,呵呵

劳动节?

北京的地铁真便宜

今天晚上花2块钱16*2站地,大半个北京了,刚回来,可累死了,还好赶上了末班车,要不就惨了,身上就10块钱,在这里祝她老爷子生日快乐,呵呵,虽然人家用不着...

鸟人

我这么个鸟人,自己都没办法,唉...

懦弱,咯色,孤僻,小人,虚荣,胆怯,庸俗,冷血

2008年4月29日星期二

被忽悠了 呵呵

被忽悠了呵呵,谢谢

啥是法儿
今儿累坏了,上午改那该死的bug,下午急匆匆跑了趟前门,刚到就公司打电话找,真他娘的倒霉,又急急忙忙敢了回来,干活,下班了,打个电话吧,呵呵,才知道原来是被忽悠了一天,唉...啥是法儿,还是那么地,只能怪自己,回家吧,呵呵
对了,今天骑的自行车,发现也不比原来远多少,当初怎么就冲动买了电动车呢,下了班,慢慢悠悠骑回来了,唉...想想会有回家的劲儿,一个人都没有,都是自个作地,受吧。

唉...最近不顺,没啥精神事儿

五一了,呵呵 ,又

2008年4月28日星期一

我怎么觉得我是那么的咯色

郁闷

做了个小活儿弄得我不得安宁,

心里有事儿,不安,做什么都没心情,烦躁

因为需要给人家去部署,跟公司说有事出去,都不好意思了,好多次了,唉,,,

这么点小事搞的我到处撞墙,老婆都跑了,怪我,太咯色,呵呵,

知道她很想让我带她出去逛街,可我真的是没有心思,又不想让她扫兴,就这么不知如何是好的过了两天

她慌慌着五一回家,我确一点心思没有,回家,向来对我没有吸引力,家里人好像也没问过我回不回去

有个哥们儿真是让我烦,格格不入,也不知是我变了,还是他变了,或许是我太敏感了,越来越咯色

妹妹与老婆的中间是我,让我这个不善维和的笨蛋自己在这发霉,好像现在也没什么,只是老婆发发牢骚,感觉有颗定时炸弹在我心中

下午把跟随我征战北京的自行车骑回来了,骑自行车,爽

自己闷在家里发呆,头疼。

我好想过个快乐的周末,好久没有了。都怪自己没能力,太嫩

以前觉得自己挺会小资的,现在怎么这么机械了呢,越来越俗了。

2008年4月27日星期日

向div中插入动画

//elm: div id

//url:flash url

//w:width

//h:height

function insertFlash(elm, url, w, h, id) {
if (!document.getElementById(elm)) return;
var str = '';
str += '<embed width="'+ w +'" height="'+ h +'" src="'+ url +'" quality="autohigh" wmode="opaque" type="application/x-shockwave-flash" plugspace="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" id='+id+'></embed>';
document.getElementById(elm).innerHTML = str;
}

2008年4月22日星期二

去掉字符串中多余的空格

import java.util.regex.Matcher; import java.util.regex.Pattern;
public class Test
{


    public static void main(String arg[])
    {
   
        String s = "abc 123    456";
        System.out.println(s);

        while(true){
       
            int index = s.indexOf(" ");
            if(index > 0){
                s = s.replaceAll(" "," ");
            }else{
                break;
            }
        }
       
        System.out.println(s);
    }

public static String replace(String inputStr, String replaceStr) {
            Pattern p = Pattern.compile(" +");
            Matcher m = p.matcher(inputStr);
            return m.replaceAll(replaceStr);
       }


}

C# 在word文档中复制表格并粘帖到下一页中

object oMissing = System.Reflection.Missing.Value;
            Microsoft.Office.Interop.Word._Application oWord;
            Microsoft.Office.Interop.Word._Document oDoc;
            oWord = new Microsoft.Office.Interop.Word.Application();
            //显示word文档
            oWord.Visible = true;
            //取得word文件模板
            object fileName = System.Windows.Forms.Application.StartupPath + "\\word.doc";
            //根据模板生成一个新文档,相当于另存为
            oDoc = oWord.Documents.Add(ref fileName, ref oMissing,
                            ref oMissing, ref oMissing);

            //复制第一个表格
            oDoc.Tables[1].Select();
            oWord.Selection.Copy();

            //在这里操作表格中的文本
            oDoc.Tables[1].Cell(1, 1).Range.Text = "这是第一个表格";

            //下一页
            object mymissing = System.Reflection.Missing.Value;
            object myunit = Microsoft.Office.Interop.Word.WdUnits.wdStory;
            oWord.Selection.EndKey(ref myunit, ref mymissing);
            object pBreak = (int)Microsoft.Office.Interop.Word.WdBreakType.wdPageBreak;
            oWord.Selection.InsertBreak(ref pBreak);

            //粘贴第一个表格
            oWord.Selection.Paste();

            oDoc.Tables[2].Cell(1, 1).Range.Text = "这是第二个表格";