需要寫個正則替換字符,網上找來個入門教程,很實用
正則表達式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,下午急匆匆跑了趟前門,剛到就公司打電話找,真他娘的倒霉,又急急忙忙敢了回來,干活,下班了,打個電話吧,呵呵,才知道原來是被忽悠了一天,唉...啥是法兒,還是那么地,只能怪自己,回家吧,呵呵
對了,今天騎的自行車,發現也不比原來遠多少,當初怎么就沖動買了電動車呢,下了班,慢慢悠悠騎回來了,唉...想想會有回家的勁兒,一個人都沒有,都是自個作地,受吧。
唉...最近不順,沒啥精神事兒
五一了,呵呵 ,又