需要写个正则替换字符,网上找来个入门教程,很实用
正则表达式30分钟入门教程
select * from (select * from apply_info order by dbms_random.value) where rownum <= 3
01 public class Test {
02 /**
03 * Simplest in Java 1.5, using the
replace method, which
04 * takes CharSequence
objects.
05 */
06 public static String
replace15(
07 String aInput, String
aOldPattern, String aNewPattern){
08 return aInput.replace(aOldPattern, aNewPattern);
09 }
10 /**
11 * Not quite as simple in Java 1.4.
The replaceAll method works,
12 * but requires more care, since it
uses regular expressions, which
13 * may contain special
characters.
14 */
15 public static String
replace14(
16 String aInput, String
aOldPattern, String aNewPattern){
17 /*
18 * The replaceAll method is a bit
dangerous to use.
19 * The aOldPattern is converted
into a regular expression.
20
* Thus, if aOldPattern may
contain characters which have
21 * special meaning to regular
expressions, then they must
22 * be 'escaped' before being
passed to replaceAll. It is
23 * easy to forget to do
this.
24 *
25 * In addition, aNewPattern treats
'$' as special characters
26 * as well: they refer to 'back
references'.
27 */
28 return aInput.replaceAll(aOldPattern, aNewPattern);
29 /*
30 Here is an alternative
implementation using Pattern and Matcher,
31 which is preferred when the same
pattern is used repeatedly
32 final Pattern pattern =
Pattern.compile( aOldPattern );
33 final Matcher matcher =
pattern.matcher( aInput );
34 return matcher.replaceAll(
aNewPattern );
35 */
36 }
37 /**
38 * If Java 1.4 is unavailable, the
following technique may be used.
39 *
40 * @param aInput is the original
String which may contain substring aOldPattern
41 * @param aOldPattern is the non-empty
substring which is to be replaced
42 * @param aNewPattern is the
replacement for aOldPattern
43 */
44 public static String
replaceOld(
45 final String aInput,
46 final String
aOldPattern,
47 final String
aNewPattern){
48 if ( aOldPattern.equals("") )
{
49
throw new
IllegalArgumentException("Old pattern must have
content.");
50 }
51 final StringBuffer result =
new
StringBuffer();
52 //startIdx and idxOld delimit various
chunks of aInput; these
53 //chunks always end where aOldPattern
begins
54 int startIdx = 0;
55
int idxOld = 0;
56 while ((idxOld = aInput.indexOf(aOldPattern, startIdx)) >= 0) {
57 //grab a part of aInput which does
not include aOldPattern
58 result.append( aInput.substring(startIdx, idxOld) );
59 //add aNewPattern to take place of
aOldPattern
60 result.append( aNewPattern );
61 //reset the startIdx to just after
the current match, to see
62 //if there are any further
matches
63 startIdx = idxOld +
aOldPattern.length();
64 }
65 //the final chunk will go to the end
of aInput
66 result.append( aInput.substring(startIdx) );
67 return result.toString();
68 }
69 /** Example: update an ip address
appearing in a link. */
70 public static void main (String[] aArguments)
{
71
String OLD_IP = "insert into LOAD_POLIINFO
(IDCARD,POLISTAT,JOINDATE,LOADNO) values
('110102197906300508','13',to_date('null
','yyyy-mm-dd'),70990)";
72 log(replaceOld(OLD_IP,"to_date('null ','yyyy-mm-dd')","null"));
73 }
74 private static void log(String
aMessage){
75 System.out.println(aMessage);
76 }
77 }
参考自:http://www.javapractices.com/topic/TopicAction.do?Id=80
http://biostar.blog.sohu.com/69732830.html
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;
}
}
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;
}
}
今儿咱民工真高产,劳动节了嘛,哈哈
真的希望像我那头猪一样啊,呵呵
睡吧,明天太阳会升起
不对,今天的太阳就要升起 呵呵
咯色的垃圾
咯色的垃圾就应该扔到无人烟的垃圾堆里,爱咋咋地去,省的惹别人一身臭
大家离我远点
我遇到什么事不能解决就慌乱,心烦,跟他娘的女人来事儿似的,呵呵,据说是
更不用说,几件事压在头上了
能够坦然的,游刃有余的处理来自各方的琐事,可能就是比较高的人了吧,呵呵
想想,周末好像有成为黑色的趋势,听着老婆不时的唠叨妹妹的这啊那啊的,不知如何是好
小系统做了半年多还没结项,开始丧失在大大那的赏识
并且占用了我所有的业余时间,老婆都要跑了
而且老扯票撒谎的出去,心都虚了,每次要编个瞎话跟他娘的下地狱似的,痛苦
太嫩....
认识我的人大都说我变了
我难以判定,好像是变了,变怎么了?不知道,大多说我变垃圾了
开始时,看电视也好,电影也好,故事也好,两个人吵架,大都是因为互相不理解,有未言明的误会,吵啊吵的不可开交,甚至不可挽回,那时我就告诉自己,遇到这样的事一定要,立刻解释清楚,静下心来坦言,消除了误会,让对方理解了,也就好了。而现在,我很不想去解释,想的是如果言明了就没意思了,唉...可能也不能一概而论,可能也要分什么事情,可能也分什么关系的人,有默契的人可能就不用解释
人啊,郁闷而又闲闲的时候就容易胡思乱想。
发现如果某人惹你不高兴了,一段时间内,你看他哪都不顺眼,呵呵
北京人儿啊,都那么自信,自信的让人都只能隐形了
只知道让人干活的公司会是什么样?就像老一辈讲求无私奉献,为实现共产而努力奋斗,呵呵,我们得到什么了呢,老一辈还得到精神上的满足,我们连精神上的都没了,加班费都不好好给报了,我日啊,老子是喜欢钱地。
开始羡慕民工了,呵呵,
可咱翅膀还没长硬,忍着吧
学习 学习 学习
心情不好时就抽烟,喝酒,可命的抽,昨晚浏览了个电影,韩国的,一帅哥爱喝酒抽烟,得了肝硬化,放下身边的工作,妈妈,女友,去疗养院了。呵呵,难道韩国有这样的规定?在我的世界不知道谁能做到去疗养院,能去医院看看,听医嘱,就是有条件的了。
从地铁出来都十一点了,看着外面一个个摆摊卖玉米的,等活儿的出租车司机,人活着比他妈狗都难。
今天公司聚餐,老总说她别看那么大岁数了,可比我们健康,让我们一定要注意身体,她每周都至少在健身房呆两个小时,呵呵,不是一个阶层的人啊,俺倒想去健身房,俺还没房住呢,咋整...
唉...内外兼忧啊
好像从开始上大学开始有五一放假这一说,大学时候的放假忘了都干啥了,只记得刚上大一的第一个十一是自己一个人在宿舍过的,大家都回家了。
毕业后的五一都该成我的受难日了,呵呵
劳动节?
今天晚上花2块钱16*2站地,大半个北京了,刚回来,可累死了,还好赶上了末班车,要不就惨了,身上就10块钱,在这里祝她老爷子生日快乐,呵呵,虽然人家用不着...
我这么个鸟人,自己都没办法,唉...
懦弱,咯色,孤僻,小人,虚荣,胆怯,庸俗,冷血
被忽悠了呵呵,谢谢
啥是法儿
今儿累坏了,上午改那该死的bug,下午急匆匆跑了趟前门,刚到就公司打电话找,真他娘的倒霉,又急急忙忙敢了回来,干活,下班了,打个电话吧,呵呵,才知道原来是被忽悠了一天,唉...啥是法儿,还是那么地,只能怪自己,回家吧,呵呵
对了,今天骑的自行车,发现也不比原来远多少,当初怎么就冲动买了电动车呢,下了班,慢慢悠悠骑回来了,唉...想想会有回家的劲儿,一个人都没有,都是自个作地,受吧。
唉...最近不顺,没啥精神事儿
五一了,呵呵 ,又