StringUtil.java 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453
  1. package com.yihu.jw.utils;
  2. import org.apache.commons.lang3.StringUtils;
  3. import javax.servlet.http.HttpServletRequest;
  4. import java.io.IOException;
  5. import java.io.StringWriter;
  6. import java.io.UnsupportedEncodingException;
  7. import java.io.Writer;
  8. import java.sql.Clob;
  9. import java.sql.SQLException;
  10. import java.util.ArrayList;
  11. import java.util.Iterator;
  12. import java.util.List;
  13. import java.util.Random;
  14. import java.util.regex.Matcher;
  15. import java.util.regex.Pattern;
  16. public class StringUtil {
  17. public static String substring(String str, int start) {
  18. return StringUtils.substring(str, start);
  19. }
  20. public static String substring(String str, int start, int end) {
  21. return StringUtils.substring(str, start, end);
  22. }
  23. public static boolean isBlank(String str) {
  24. return StringUtils.isBlank(str);
  25. }
  26. public static String toString(Object obj) {
  27. if (obj == null) {
  28. return null;
  29. }
  30. return obj.toString();
  31. }
  32. public static String trimLeft(String value) {
  33. if (value == null)
  34. return "";
  35. String result = value;
  36. char ch[] = result.toCharArray();
  37. int index = -1;
  38. for (int i = 0; i < ch.length; i++) {
  39. if (Character.isWhitespace(ch[i])) {
  40. index = i;
  41. } else {
  42. break;
  43. }
  44. }
  45. if (index != -1) {
  46. result = result.substring(index + 1);
  47. }
  48. return result;
  49. }
  50. /**
  51. * ?��??????????????????
  52. *
  53. * @param value ?????
  54. * @return String src????????
  55. */
  56. public static String trimRight(String value) {
  57. if (value == null)
  58. return "";
  59. String result = value;
  60. char ch[] = result.toCharArray();
  61. int endIndex = -1;
  62. for (int i = ch.length - 1; i > -1; i--) {
  63. if (Character.isWhitespace(ch[i])) {
  64. endIndex = i;
  65. } else {
  66. break;
  67. }
  68. }
  69. if (endIndex != -1) {
  70. result = result.substring(0, endIndex);
  71. }
  72. return result;
  73. }
  74. /**
  75. * ***************************************************** ??
  76. * ??????????????????"0",?????????? ????????param str:???????????? param len???????????? ?? ???Stirng
  77. * <p/> ??��????? ??????? ******************************************************
  78. */
  79. public static String fillHeadCharsLen(String strOri, int len) {
  80. return fillHeadCharsLen(strOri, "0", len);
  81. }
  82. /**
  83. * ***************************************************** ??
  84. * ???????????????????"0",?????????? ????????param str:???????????? param len???????????? ?? ???Stirng
  85. * <p/> ??��????? ??????? ******************************************************
  86. */
  87. public static String fillBackCharsLen(String strOri, int len) {
  88. return fillBackCharsLen(strOri, "0", len);
  89. }
  90. /**
  91. * ***************************************************** ??
  92. * ??????????????????????????,?????????? ????????param str:???????????? param subStr:????????????
  93. * param len???????????? ?? ???Stirng <p/> ??��????? ???????
  94. * ******************************************************
  95. */
  96. public static String fillHeadCharsLen(String strOri, String subStr, int len) {
  97. if (strOri == null || strOri.trim().length() == 0) {
  98. strOri = "";
  99. }
  100. if (subStr == null) {
  101. subStr = " ";
  102. }
  103. String fillStr = "";
  104. for (int i = 0; i < len; i++) {
  105. fillStr = fillStr + subStr;
  106. }
  107. subStr = fillStr + strOri;
  108. return (subStr.substring(subStr.length() - len, subStr.length()));
  109. }
  110. /**
  111. * ***************************************************** ??
  112. * ???????????????????????????,?????????? ????????param str:???????????? param subStr:????????????
  113. * param len???????????? ?? ???Stirng <p/> ??��????? ???????
  114. * ******************************************************
  115. */
  116. public static String fillBackCharsLen(String strOri, String subStr, int len) {
  117. if (strOri == null || strOri.trim().length() == 0) {
  118. strOri = "";
  119. }
  120. if (subStr == null) {
  121. subStr = " ";
  122. }
  123. String fillStr = "";
  124. for (int i = 0; i < len; i++) {
  125. fillStr = fillStr + subStr;
  126. }
  127. subStr = strOri + fillStr;
  128. return (subStr.substring(0, len));
  129. }
  130. /**
  131. * ***************************************************** ?? ??????????????????"0"
  132. * ????????param str:???????????? param counter??????????? ?? ???Stirng <p/> ??��????? ???????
  133. * ******************************************************
  134. */
  135. public static String fillHeadChars(String strOri, int counter) {
  136. return fillHeadChars(strOri, "0", counter);
  137. }
  138. /**
  139. * ***************************************************** ?? ???????????????????"0"
  140. * ????????param str:???????????? param counter??????????? ?? ???Stirng <p/> ??��????? ???????
  141. * ******************************************************
  142. */
  143. public static String fillBackChars(String strOri, int counter) {
  144. return fillBackChars(strOri, "0", counter);
  145. }
  146. /**
  147. * ***************************************************** ?? ??????????????????????????
  148. * ????????param str:???????????? param subStr:???????????? param counter??????????? ??
  149. * ???Stirng <p/> ??��????? ???????
  150. * ******************************************************
  151. */
  152. public static String fillHeadChars(String strOri, String subStr, int counter) {
  153. if (strOri == null || strOri.trim().length() == 0) {
  154. strOri = "";
  155. }
  156. if (counter <= 0 || subStr == null) {
  157. return strOri;
  158. }
  159. String fillStr = "";
  160. for (int i = 0; i < counter; i++) {
  161. fillStr = fillStr + subStr;
  162. }
  163. return (fillStr + strOri);
  164. }
  165. /**
  166. * ***************************************************** ?? ???????????????????????????
  167. * ????????param str:???????????? param subStr:???????????? param counter??????????? ??
  168. * ???Stirng <p/> ??��????? ???????
  169. * ******************************************************
  170. */
  171. public static String fillBackChars(String strOri, String subStr, int counter) {
  172. if (strOri == null || strOri.trim().length() == 0) {
  173. strOri = "";
  174. }
  175. if (counter <= 0 || subStr == null) {
  176. return strOri;
  177. }
  178. String fillStr = "";
  179. for (int i = 0; i < counter; i++) {
  180. fillStr = fillStr + subStr;
  181. }
  182. return (strOri + fillStr);
  183. }
  184. /**
  185. * ***************************************************** ??
  186. * ????��???????????????null(???????) ????????param str:???????????? ????????? ?? ??????null??true;
  187. * ?????false <p/> ??��?????20051220 ???????
  188. * ******************************************************
  189. */
  190. public static boolean isEmpty(Object strObj) {
  191. if (strObj == null || strObj.toString().trim().length() < 1) {
  192. return true;
  193. } else {
  194. return false;
  195. }
  196. }
  197. /**
  198. * ***************************************************** ??
  199. * ????��??????????????????null????(???????)?? ????????param str:???��??????? ????????? ??
  200. * ???true?????false????? <p/> ??��?????20051220 ???????
  201. * ******************************************************
  202. */
  203. public static boolean isStrEmpty(String str) {
  204. if ((str == null) || (str.trim().length() < 1) || "null".endsWith(str.toLowerCase())) {
  205. return true;
  206. } else {
  207. return false;
  208. }
  209. }
  210. /**
  211. * ***************************************************** ??
  212. * ????????????????????????????????null????? ????????param str:???????????? ????????? ??
  213. * ???????????????????????? <p/> ??��?????20051220 ???????
  214. * ******************************************************
  215. */
  216. public static String getValue(String str) {
  217. if (str == null) {
  218. return "";
  219. }
  220. if (str.trim().length() <= 0)
  221. return "";
  222. str = "H" + str;
  223. str = str.trim();
  224. str = str.substring(1);
  225. return str;
  226. }
  227. /**
  228. * ***************************************************** ?? ????��?????????????????????
  229. * ????????param text:???��?????????param len:????????? ????????? ?? ???return
  230. * true??��??????false??????????? <p/> ??��?????20051220 ???????
  231. * ******************************************************
  232. */
  233. public static boolean chkTextLen(String text, int len) {
  234. if (text == null || text.length() > len) {
  235. return false;
  236. } else {
  237. return true;
  238. }
  239. }
  240. /**
  241. * ***************************************************** ??
  242. * ????��??????????????????????????? ????????param text:???��?????????param len:????????? ????????? ??
  243. * ???return true??��??????false??????????? <p/> ??��?????20051220 ???????
  244. * ******************************************************
  245. */
  246. public static boolean chkTextTrimLen(String text, int len) {
  247. if (text == null || text.trim().length() > len) {
  248. return false;
  249. } else {
  250. return true;
  251. }
  252. }
  253. /**
  254. * ***************************************************** ??
  255. * ????��???????????????english ????????param text:???��????????? ????????? ?? ???return
  256. * true???????false:????????????????????? <p/> ??��?????20051220 ???????
  257. * ******************************************************
  258. */
  259. public static boolean isStrEn(String text) {
  260. for (int i = 0; i < text.length(); i++) {
  261. if (text.charAt(i) > 127) {
  262. return false;
  263. }
  264. }
  265. return true;
  266. }
  267. /**
  268. * ***************************************************** ?? ????��????????????????
  269. * ????????param ch:???��????? ????????? ?? ???return true???????false:?????? <p/>
  270. * ??��?????20051220 ???????
  271. * ******************************************************
  272. */
  273. public static boolean isCharNum(char ch) {
  274. if (ch > 47 && ch < 58) {
  275. return true;
  276. } else {
  277. return false;
  278. }
  279. }
  280. /**
  281. * ***************************************************** ??
  282. * ????��?????????????��????????? ????????param str:???��??????? ????????? ?? ???return
  283. * true??Null?????????????false:??????? <p/> ??��?????20051220 ???????
  284. * ******************************************************
  285. */
  286. public static boolean isStrNum(String str) {
  287. if (isStrEmpty(str)) {
  288. return true;
  289. }
  290. boolean notNum = false;
  291. for (int i = 0; i < str.length(); i++) {
  292. if (!isCharNum(str.charAt(i))) {
  293. notNum = true;
  294. }
  295. }
  296. return !notNum;
  297. }
  298. /**
  299. * ***************************************************** ??
  300. * ????��?????????????��????????? ????????param strSrc:???��??????? ????????? ?? ???return
  301. * true??????????false:????????? <p/> ??��?????20051220 ???????
  302. * ******************************************************
  303. */
  304. public static boolean isNum(String strSrc) throws Exception {
  305. for (int i = 0; i < strSrc.length(); i++) {
  306. if (!isCharNum(strSrc.charAt(i)))
  307. return false;
  308. }
  309. return true;
  310. }
  311. /**
  312. * ***************************************************** ?? ????��??????????????????
  313. * ????????param ch:???��????? ????????? ?? ???return true????????????false:?????????? <p/>
  314. * ??��?????20051220 ???????
  315. * ******************************************************
  316. */
  317. public static boolean isCharLetter(char ch) {
  318. if ((ch >= 65 && ch <= 90) && (ch >= 97 && ch <= 122)) {
  319. return true;
  320. } else {
  321. return false;
  322. }
  323. }
  324. /**
  325. * ***************************************************** ?? ????��?????????????????????
  326. * ????????param str:???��??????? ????????? ?? ???return true??NULL???��?????????false:?????????
  327. * <p/> ??��?????20051220 ???????
  328. * ******************************************************
  329. */
  330. public static boolean isStrLetter(String str) {
  331. if (isStrEmpty(str))
  332. return true;
  333. boolean notLetter = false;
  334. for (int i = 0; i < str.length(); i++) {
  335. if (!isCharLetter(str.charAt(i))) {
  336. notLetter = true;
  337. }
  338. }
  339. return !notLetter;
  340. }
  341. /**
  342. * ***************************************************** ??
  343. * ?????????????????????????????? ????????param src:?????????? ????????? ?? ???return
  344. * ??????????????????????????? <p/> ??��?????20051220 ???????
  345. * ******************************************************
  346. */
  347. public static char strToChar(String src) {
  348. src = src.trim();
  349. char result = src.charAt(0);
  350. return result;
  351. }
  352. /**
  353. * ***************************************************** ??
  354. * ??????????????????????ASCII?? ????????param sql:???????sql?????? ????????? ?? ?????????????? <p/>
  355. * ??��?????20051220 ???????
  356. * ******************************************************
  357. */
  358. public static String encodeSQL(String sql) {
  359. StringBuffer tempBuff = new StringBuffer();
  360. for (int i = 0; i < sql.length(); i++) {
  361. tempBuff.append(Integer.toHexString(sql.charAt(i)));
  362. }
  363. return tempBuff.toString();
  364. }
  365. /**
  366. * ***************************************************** ??
  367. * ??????????ASCII????????????????? ????????param encoded:???????????? ????????? ?? ?????????????? <p/>
  368. * ??��?????20051220 ???????
  369. * ******************************************************
  370. */
  371. public static String decodeSQL(String encoded) {
  372. StringBuffer tempBuff = new StringBuffer();
  373. for (int i = 0; i < encoded.length(); i += 2) {
  374. tempBuff.append((char) Integer.parseInt(
  375. encoded.substring(i, i + 2), 16));
  376. }
  377. return tempBuff.toString();
  378. }
  379. /**
  380. * ***************************************************** ?? ?????????��??
  381. * ????????param path1:????��????param context1:?????? ????????? ?? ???return ???��?? <p/>
  382. * ??��?????20051220 ???????
  383. * ******************************************************
  384. */
  385. public static String getAbsolutePath(String path1, String context1) {
  386. int i1 = path1.indexOf(context1);
  387. if (i1 < 0) {
  388. return path1;
  389. } else {
  390. return path1.substring(path1.indexOf(context1) + context1.length());
  391. }
  392. }
  393. /**
  394. * ***************************************************** ?? ????????? ????????param
  395. * str1:???????????????param sindex:???��???param eindex:????��?? ????????? ??
  396. * ???????????��????????��???????????????????��??��??0?????????��????????? <p/> ??��?????20051220 ???????
  397. * ******************************************************
  398. */
  399. public static String getSubString(String str1, int sindex, int eindex) {
  400. if (str1 == null) {
  401. return "";
  402. }
  403. if (str1.trim().length() <= 0)
  404. return "";
  405. if (str1.length() > sindex) {
  406. if (eindex >= 0)
  407. return str1.substring(sindex, eindex);
  408. else if (eindex < 0)
  409. return str1.substring(sindex);
  410. }
  411. return "";
  412. }
  413. /**
  414. * ***************************************************** ??
  415. * ????????????????????????��??????????????? ????????param strs:???????????????�param size1:?????????�A??
  416. * ????????? ?? ???return ??????????????? <p/> ??��?????20051220 ???????
  417. * ******************************************************
  418. */
  419. public static String[] getValues(String[] strs, int size1) {
  420. String[] strs1 = new String[size1];
  421. for (int i = 0; i < size1; i++) {
  422. strs1[i] = "";
  423. }
  424. if (strs == null) {
  425. return strs1;
  426. } else {
  427. if (strs.length < size1) {
  428. for (int i = 0; i < strs.length; i++) {
  429. strs1[i] = strs[i];
  430. }
  431. return strs1;
  432. } else {
  433. return strs;
  434. }
  435. }
  436. }
  437. /**
  438. * ***************************************************** ?? ????????????�I????
  439. * ????????param strSource ???�I?????????param strFrom ????????param strTo ???????? ????????? ??
  440. * ????�I???????? <p/> ??��?????20051220 ???????
  441. * ******************************************************
  442. */
  443. public static String replaceStrAll(String strSource, String strFrom,
  444. String strTo) {
  445. String strDest = "";
  446. int intFromLen = strFrom.length();
  447. int intPos;
  448. while ((intPos = strSource.indexOf(strFrom)) != -1) {
  449. strDest = strDest + strSource.substring(0, intPos);
  450. strDest = strDest + strTo;
  451. strSource = strSource.substring(intPos + intFromLen);
  452. }
  453. strDest = strDest + strSource;
  454. return strDest;
  455. }
  456. public static String replaceStr(String strTarget, String strNew) {
  457. int iIndex = -1;
  458. while (true) {
  459. iIndex = strTarget.indexOf('\n');
  460. if (iIndex < 0) {
  461. break;
  462. }
  463. String strTemp = null;
  464. strTemp = strTarget.substring(0, iIndex);
  465. strTarget = strTemp + strNew + strTarget.substring(iIndex + 1);
  466. }
  467. return strTarget;
  468. }
  469. /**
  470. * ***************************************************** ??
  471. * ????��????????????????��?????? ????????param str1 ?????????????param strarray ??????????????�
  472. * ????????? ?? ???return true??????;false??��???? <p/> ??��?????20051220 ???????
  473. * ******************************************************
  474. */
  475. public static boolean includestr(String str1, String[] strarray) {
  476. if (strarray == null || strarray.length <= 0)
  477. return false;
  478. for (int i = 0; i < strarray.length; i++) {
  479. if (strarray[i] == null) {
  480. if (str1 == null)
  481. return true;
  482. else
  483. continue;
  484. }
  485. if (strarray[i].trim().equals(str1)) {
  486. return true;
  487. }
  488. }
  489. return false;
  490. }
  491. /**
  492. * ***************************************************** ??
  493. * ?????\n?????????????????????????�?????\r ????????param fvalue ???????????? ????????? ?? ???return
  494. * ?????????? <p/> ??��?????20051220 ???????
  495. * ******************************************************
  496. */
  497. public static String[] getAreaValues(String fvalue) {
  498. String tmpstr = fvalue;
  499. int i = 0;
  500. if (tmpstr == null)
  501. return null;
  502. if (tmpstr.trim().equals(""))
  503. return null;
  504. while (tmpstr.indexOf("\n") >= 0) {
  505. i++;
  506. tmpstr = tmpstr.substring(tmpstr.indexOf("\n") + 1);
  507. }
  508. if (tmpstr.trim().equals("")) {
  509. i--;
  510. }
  511. String[] fvalues = new String[i + 1];
  512. tmpstr = fvalue;
  513. i = 0;
  514. while (tmpstr.indexOf("\n") >= 0) {
  515. fvalues[i] = tmpstr.substring(0, tmpstr.indexOf("\n"));
  516. if (fvalues[i].indexOf("\r") >= 0)
  517. fvalues[i] = fvalues[i].substring(0, fvalues[i].indexOf("\r"));
  518. i++;
  519. tmpstr = tmpstr.substring(tmpstr.indexOf("\n") + 1);
  520. }
  521. if (!tmpstr.trim().equals(""))
  522. fvalues[i] = tmpstr;
  523. return fvalues;
  524. }
  525. /**
  526. * ***************************************************** ?? ???????????��?|????\n
  527. * ????????param fvalue ???????????? ????????? ?? ?????????????? <p/> ??��?????20051220 ???????
  528. * ******************************************************
  529. */
  530. public static String getrealAreaValues(String fvalue) {
  531. String tmpstr = fvalue;
  532. String returnstr = "";
  533. if (tmpstr == null)
  534. return null;
  535. if (tmpstr.trim().equals(""))
  536. return "";
  537. while (tmpstr.indexOf("|") > 0) {
  538. returnstr += tmpstr.substring(0, tmpstr.indexOf("|")) + "\n";
  539. tmpstr = tmpstr.substring(tmpstr.indexOf("|") + 1);
  540. }
  541. return returnstr;
  542. }
  543. /**
  544. * ***************************************************** ??
  545. * ?????????????��??��???????????? ????????param strInput ??????????????param chr ????????? ????????? ??
  546. * ???return ???????????? <p/> ??��?????20051220 ???????
  547. * ******************************************************
  548. */
  549. public static int countChar(String strInput, char chr) {
  550. int iCount = 0;
  551. char chrTmp = ' ';
  552. if (strInput.trim().length() == 0)
  553. return 0;
  554. // ?????????????????
  555. for (int i = 0; i < strInput.length(); i++) {
  556. chrTmp = strInput.charAt(i);
  557. if (chrTmp == chr) {
  558. iCount++;
  559. }
  560. }
  561. return iCount;
  562. }
  563. /**
  564. * ***************************************************** ?? ??????????????????????????
  565. * ????????param strs ???????????????? ????????? ?? ????? <p/> ??��?????20051220 ???????
  566. * ******************************************************
  567. */
  568. public static String strArrayToStr(String[] strs) {
  569. return strArrayToStr(strs, null);
  570. }
  571. /**
  572. * ***************************************************** ?? ??????��???????????????????
  573. * ????????param strs ???????????????? ????????? ?? ????? <p/> ??��?????20051220 ???????
  574. * ******************************************************
  575. */
  576. public static void printStrs(String[] strs) {
  577. for (int i = 0; i < strs.length; i++) {
  578. System.out.println(strs[i]);
  579. }
  580. }
  581. /**
  582. * ***************************************************** ??
  583. * ???????????��??????��??????????????????? ????????param strs ?????????????????? ????????? ?? ????? <p/>
  584. * ??��?????20051220 ???????
  585. * ******************************************************
  586. */
  587. public static void printDualStr(String[][] dualStr) {
  588. for (int i = 0; i < dualStr.length; i++) {
  589. for (int j = 0; j < dualStr[i].length; j++) {
  590. System.out.print(dualStr[i][j] + " ");
  591. }
  592. System.out.println();
  593. }
  594. }
  595. /**
  596. * ***************************************************** ??
  597. * ???????????????????????��???��????��???? ????????param dualStr ??????????? ????????? ?? ???return
  598. * ???????????? <p/> ??��?????20051220 ???????
  599. * ******************************************************
  600. */
  601. public static String[][] rowToColumn(String[][] dualStr) {
  602. String[][] returnDualStr = null;
  603. if (dualStr != null) {
  604. returnDualStr = new String[dualStr[0].length][dualStr.length];
  605. for (int i = 0; i < dualStr.length; i++)
  606. for (int j = 0; j < dualStr[0].length; j++)
  607. returnDualStr[j][i] = dualStr[i][j];
  608. }
  609. return returnDualStr;
  610. }
  611. /**
  612. * ***************************************************** ??
  613. * ????????????????????String?????��???????????????? ????????param inStr ?????????? ????????? ?? ???return
  614. * ??????????????? <p/> ??��?????20051220 ???????
  615. * ******************************************************
  616. */
  617. public static String latinString(String inStr) {
  618. String res = inStr;
  619. if (null == res)
  620. return null;
  621. res = replaceStrAll(res, "\"", "\\\"");
  622. res = replaceStrAll(res, "'", "\\'");
  623. return res;
  624. }
  625. /**
  626. * ***************************************************** ?? ?????????????��???�I???????
  627. * ????????param String strTarget, String strNew ????????? ?? ???return String
  628. * ????????�I????? <p/> ??��?????20051220 ???????
  629. * ******************************************************
  630. */
  631. public static String replaceWhiteSpace(String strTarget, String strNew) {
  632. int iIndex = -1;
  633. while (true) {
  634. char cRep = 32;
  635. iIndex = strTarget.indexOf(cRep);
  636. if (iIndex < 0) {
  637. break;
  638. }
  639. String strTemp = null;
  640. strTemp = strTarget.substring(0, iIndex);
  641. strTarget = strTemp + strNew + strTarget.substring(iIndex + 1);
  642. }
  643. return strTarget;
  644. }
  645. /**
  646. * ***************************************************** ??
  647. * ?????????��?????????��????��?????????????��????��?????????��???? ????????param amount ???????, param
  648. * length ?????��??��???? ????????? ?? ???return ??????????????? <p/> ??��?????20051220 ???????
  649. * ******************************************************
  650. */
  651. public static String double2str(double amount, int length) {
  652. String strAmt = Double.toString(amount);
  653. int pos = strAmt.indexOf('.');
  654. if (pos != -1 && strAmt.length() > length + pos + 1)
  655. strAmt = strAmt.substring(0, pos + length + 1);
  656. return strAmt;
  657. }
  658. /**
  659. * ***************************************************** ??
  660. * ???????chr?????????????String???????split???????"|"??????? ????????param str ??????????,param
  661. * chr ?????? ????????? ?? ???return String[] ??????????????,????????????|?????????? <p/>
  662. * ??��?????20051220 ???????
  663. * ******************************************************
  664. */
  665. public static String[] doSplit(String str, char chr) {
  666. int iCount = 0;
  667. char chrTmp = ' ';
  668. // ?????????????????
  669. for (int i = 0; i < str.length(); i++) {
  670. chrTmp = str.charAt(i);
  671. if (chrTmp == chr) {
  672. iCount++;
  673. }
  674. }
  675. String[] strArray = new String[iCount];
  676. for (int i = 0; i < iCount; i++) {
  677. int iPos = str.indexOf(chr);
  678. if (iPos == 0) {
  679. strArray[i] = "";
  680. } else {
  681. strArray[i] = str.substring(0, iPos);
  682. }
  683. str = str.substring(iPos + 1); // ??iPos+1??????,str????????��
  684. }
  685. return strArray;
  686. }
  687. /**
  688. * ***************************************************** ??
  689. * ???????s?????????????String???????split???????"|"??????? ????????param str ??????????,param s
  690. * ???????? ????????? ?? ???return String[] ??????????????,??????????|?????????? <p/>
  691. * ??��?????20051220 ???????
  692. * ******************************************************
  693. */
  694. public static String[] strSplit(String src, String splitchar) {
  695. int resultSize = 0;
  696. int len = src.length();
  697. int idx = 0;
  698. String strTemp = "";
  699. for (int i = 0; i < len; i++) {
  700. if (src.substring(i, i + 1).equals(splitchar)) {
  701. resultSize++;
  702. }
  703. }
  704. if ((len > 1) & (!src.substring(len - 1, len).equals(splitchar))) {
  705. resultSize++;
  706. }
  707. String result[] = new String[resultSize];
  708. for (int i = 0; i < len; i++) {
  709. if (src.substring(i, i + 1).equals(splitchar)) {
  710. result[idx] = strTemp;
  711. idx++;
  712. strTemp = "";
  713. } else {
  714. strTemp = String.valueOf(strTemp)
  715. + String.valueOf(src.charAt(i));
  716. }
  717. }
  718. if (!strTemp.equals("")) {
  719. result[idx] = strTemp;
  720. }
  721. return result;
  722. }
  723. /**
  724. * ***************************************************** ??
  725. * ???????strSeparator?????????????????????��??????? ????????param strToSplit ??????????,param
  726. * strSeparator ????????,param iLimit ?????�� ????????? ?? ???return String[] ??????????????
  727. * <p/> ??��?????20051220 ???????
  728. * ******************************************************
  729. */
  730. public static String[] split(String strToSplit, String strSeparator,
  731. int iLimit) {
  732. ArrayList tmpList = new ArrayList();
  733. int iFromIndex = 0;
  734. int iCurIndex = strToSplit.length();
  735. String strUnitInfo = "";
  736. int iCurCounts = 0;
  737. while ((iCurIndex != -1) && (iFromIndex < strToSplit.length())
  738. && (iCurCounts < iLimit)) {
  739. iCurIndex = strToSplit.indexOf(strSeparator, iFromIndex);
  740. if (iCurIndex == -1) {
  741. strUnitInfo = strToSplit.substring(iFromIndex, strToSplit
  742. .length());
  743. } else {
  744. strUnitInfo = strToSplit.substring(iFromIndex, iCurIndex);
  745. iFromIndex = iCurIndex + 1;
  746. }
  747. tmpList.add(strUnitInfo);
  748. iCurCounts++;
  749. }
  750. int iCounts = tmpList.size();
  751. String tmpArray[] = new String[iCounts];
  752. for (int i = 0; i < iCounts; i++) {
  753. tmpArray[i] = (String) tmpList.get(i);
  754. }
  755. return tmpArray;
  756. }
  757. /**
  758. * ***************************************************** ??
  759. * ????????????��????????????????????...???? ????????param src ???????????,param len ?????�� ????????? ??
  760. * ???return String ??��????????????????????...??????????? <p/> ??��?????20051220 ???????
  761. * ******************************************************
  762. */
  763. public static String strIntercept(String src, int len) {
  764. if (src == null) {
  765. return "";
  766. }
  767. if (src.length() > len) {
  768. src = String.valueOf(String.valueOf(src.substring(0, len))).concat(
  769. "...");
  770. }
  771. return src;
  772. }
  773. /**
  774. * ***************************************************** ??
  775. * ?????????????ISO8859_1???? ????????param str_in ??????????????? ????????? ?? ???return String
  776. * ????????????? <p/> ??��?????20051220 ???????
  777. * ******************************************************
  778. */
  779. public static String strtochn(String str_in) {
  780. try {
  781. String temp_p = str_in;
  782. if (temp_p == null) {
  783. temp_p = "";
  784. }
  785. String temp = "";
  786. if (!temp_p.equals("")) {
  787. byte[] byte1 = temp_p.getBytes("ISO8859_1");
  788. temp = new String(byte1);
  789. }
  790. return temp;
  791. } catch (Exception e) {
  792. }
  793. return "null";
  794. }
  795. /**
  796. * ***************************************************** ??
  797. * ?????ISO8859_1????????GBK???? ????????param strvalue ??????????????? ????????? ?? ???return
  798. * String ????????????? ???????
  799. * ******************************************************
  800. */
  801. public static String ISO2GBK(String strvalue) {
  802. try {
  803. if (strvalue == null)
  804. return null;
  805. else {
  806. strvalue = new String(strvalue.getBytes("ISO8859_1"), "GBK");
  807. return strvalue;
  808. }
  809. } catch (Exception e) {
  810. return null;
  811. }
  812. }
  813. /**
  814. * ***************************************************** ??
  815. * ?????????????????????��?????? ????????param str ??????????????? ????????? ?? ???return String
  816. * ????????????? ??????? ******************************************************
  817. */
  818. public static String cnCodeTrans(String str) {
  819. String s = "";
  820. try {
  821. s = new String(str.getBytes("GB2312"), "8859_1");
  822. } catch (UnsupportedEncodingException a) {
  823. System.out.print("chinese thansform exception");
  824. }
  825. return s;
  826. }
  827. /**
  828. * ***************************************************** ??
  829. * ????��?????????????????STaaaa????ST****** ????????param strSource???????????????param
  830. * strRule???? ????????? ?? ???return false:???????????true:????????? ???????
  831. * ******************************************************
  832. */
  833. public static boolean judgeMatch(String strSource, String strRule) {
  834. int i = 0;
  835. // ????????��?
  836. if ((null == strSource) || (strSource.length() == 0))
  837. return false;
  838. // ????????��?
  839. if ((null == strRule) || (strRule.length() == 0))
  840. return false;
  841. // ??????????
  842. if (strSource.length() > strRule.length())
  843. return false;
  844. // ??��???��?
  845. for (i = 0; i < strRule.length(); i++) {
  846. // ?????????
  847. if (strSource.length() < i + 1) {
  848. break;
  849. }
  850. if ((strRule.charAt(i) != '*')
  851. && (strSource.charAt(i) != strRule.charAt(i))) {
  852. return false;
  853. }
  854. }
  855. // ??????????????????????????????'*'?????????
  856. for (; i < strRule.length(); i++) {
  857. if (strRule.charAt(i) != '*')
  858. return false;
  859. }
  860. return true;
  861. }
  862. public static String column2Property(String column) {
  863. column = column.toLowerCase();
  864. int i = column.indexOf("_");
  865. while (i != -1) {
  866. if (i != column.length() - 1) {
  867. char temp = column.charAt(i + 1);
  868. String strTemp = String.valueOf(temp);
  869. column = column.replaceFirst("_" + strTemp, strTemp
  870. .toUpperCase());
  871. i = column.indexOf("_");
  872. } else {
  873. break;
  874. }
  875. }
  876. return column;
  877. }
  878. public static String strArrayToStr(String[] strs, String separator) {
  879. StringBuffer returnstr = new StringBuffer("");
  880. if (strs == null)
  881. return "";
  882. if (separator == null)
  883. separator = "";
  884. for (int i = 0; i < strs.length; i++) {
  885. returnstr.append(strs[i]);
  886. if (i < strs.length - 1)
  887. returnstr.append(separator);
  888. }
  889. return returnstr.toString();
  890. }
  891. public static String objectArrayToStr(Object[] objects, String separator) {
  892. StringBuffer returnstr = new StringBuffer("");
  893. if (objects == null)
  894. return "";
  895. if (separator == null)
  896. separator = "";
  897. for (int i = 0; i < objects.length; i++) {
  898. returnstr.append(String.valueOf(objects[i]));
  899. if (i < objects.length - 1)
  900. returnstr.append(separator);
  901. }
  902. return returnstr.toString();
  903. }
  904. public static String listToStr(List element, String separator) {
  905. StringBuffer returnstr = new StringBuffer("");
  906. if (element == null)
  907. return "";
  908. if (separator == null)
  909. separator = "";
  910. Iterator it = element.iterator();
  911. while (it.hasNext()) {
  912. returnstr.append(String.valueOf(it.next()));
  913. if (it.hasNext())
  914. returnstr.append(separator);
  915. }
  916. return returnstr.toString();
  917. }
  918. public static String[] listToStrArray(List element) {
  919. if (element == null || element.size() == 0)
  920. return null;
  921. Iterator it = element.iterator();
  922. String[] strArray = new String[element.size()];
  923. int i = 0;
  924. while (it.hasNext()) {
  925. strArray[i] = String.valueOf(it.next());
  926. i++;
  927. }
  928. return strArray;
  929. }
  930. public static List strToList(String str, String separator) {
  931. if (str == null || str.equals(""))
  932. return null;
  933. if (separator == null)
  934. separator = "";
  935. String[] strArr = str.split(separator);
  936. int size = strArr.length;
  937. List list = new ArrayList();
  938. for (int i = 0; i < size; i++) {
  939. list.add(strArr[i]);
  940. }
  941. return list;
  942. }
  943. public static StringBuffer populate(StringBuffer bf, String value,
  944. boolean isNotLast) {
  945. if (value == null) {
  946. return bf;
  947. }
  948. // ???????????????????�I??????????????????????????????SQL???????????
  949. System.out.println(value.replaceAll("'", "''"));
  950. bf.append("'").append(value.replaceAll("'", "''")).append("'");
  951. if (isNotLast)
  952. bf.append(",");
  953. return bf;
  954. }
  955. public static boolean isExist(String str, String substr, String sepatator) {
  956. if (str == null || str.trim().equals(""))
  957. return false;
  958. if (substr == null || substr.trim().equals(""))
  959. return false;
  960. String[] strArr = str.split(sepatator);
  961. int size = strArr.length;
  962. for (int i = 0; i < size; i++) {
  963. if (strArr[i].equals(substr))
  964. return true;
  965. }
  966. return false;
  967. }
  968. public static boolean isExist(String str, String substr) {
  969. return isExist(str, substr, ",");
  970. }
  971. public static String leftInclude(String str) {
  972. if (str == null || str.equals(""))
  973. return str;
  974. return str + "%";
  975. }
  976. public static String rightInclude(String str) {
  977. if (str == null || str.equals(""))
  978. return str;
  979. return "%" + str;
  980. }
  981. public static String include(String str) {
  982. if (str == null || str.equals(""))
  983. return str;
  984. return "%" + str + "%";
  985. }
  986. /**
  987. * ???????????????????????????????
  988. *
  989. * @param source String ?????
  990. * @param target String ????????
  991. * @return String ???
  992. */
  993. public static String nvl(Object source, Object target) {
  994. return source != null ? String.valueOf(source)
  995. : (target != null ? String.valueOf(target) : null);
  996. }
  997. /**
  998. * ??clob??????????????
  999. *
  1000. * @param clobValue
  1001. * @return
  1002. * @throws SQLException
  1003. */
  1004. public static String clob2Str(Object clobValue) throws SQLException {
  1005. return ((Clob) clobValue).getSubString(1, (int) ((Clob) clobValue)
  1006. .length());
  1007. }
  1008. /**
  1009. * ???web????????Ip
  1010. *
  1011. * @param request
  1012. * @return
  1013. */
  1014. public static String getRemoteAddr(HttpServletRequest request) {
  1015. String ip = request.getHeader("x-forwarded-for");
  1016. if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
  1017. ip = request.getHeader("Proxy-Client-IP");
  1018. }
  1019. if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
  1020. ip = request.getHeader("WL-Proxy-Client-IP");
  1021. }
  1022. if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
  1023. ip = request.getRemoteAddr();
  1024. }
  1025. return ip;
  1026. }
  1027. public static String hideFlowStr(String str, int maxLen) {
  1028. if (str == null || maxLen == 0) {
  1029. return "";
  1030. }
  1031. if (str.length() > maxLen) {
  1032. str = str.substring(0, maxLen) + "...";
  1033. }
  1034. return str;
  1035. }
  1036. /**
  1037. * ???????????????
  1038. *
  1039. * @param str
  1040. * @return
  1041. */
  1042. public static String escapeLuceneSpecialCharacters(String str) {
  1043. if (str == null) {
  1044. return null;
  1045. }
  1046. try {
  1047. StringWriter writer = new StringWriter(str.length() * 2);
  1048. escapeLuceneSpecialCharacterString(writer, str);
  1049. return writer.toString();
  1050. } catch (IOException ex) {
  1051. //LogService.getLogger(StringUtil.class).error(ex.getMessage());
  1052. return null;
  1053. }
  1054. }
  1055. private static void escapeLuceneSpecialCharacterString(Writer out,
  1056. String str) throws IOException {
  1057. if (str == null) {
  1058. return;
  1059. }
  1060. int sz = str.length();
  1061. for (int i = 0; i < sz; i++) {
  1062. char ch = str.charAt(i);
  1063. /*
  1064. * Reference link:
  1065. * http://lucene.apache.org/java/docs/queryparsersyntax.html Lucene
  1066. * supports escaping special characters that are part of the query
  1067. * syntax. The current list special characters are: + - && || ! ( ) { } [ ] ^ " ~ * ? : \
  1068. * To escape these character use the \ before the character.
  1069. */
  1070. switch (ch) {
  1071. case '+':
  1072. case '-':
  1073. case '!':
  1074. case '(':
  1075. case ')':
  1076. case '{':
  1077. case '}':
  1078. case '[':
  1079. case ']':
  1080. case '^':
  1081. case '\"':
  1082. case '~':
  1083. case '*':
  1084. case '?':
  1085. case ':':
  1086. case '\\':
  1087. out.write('\\');
  1088. out.write(ch);
  1089. break;
  1090. case '&':
  1091. case '|':
  1092. // check if it is '&&' or '||' ~ check if the next char is '&'
  1093. // or '|'
  1094. if ((i + 1) < sz && str.charAt(i + 1) == ch) {
  1095. out.write('\\');
  1096. out.write(ch);
  1097. i++;
  1098. }
  1099. out.write(ch);
  1100. break;
  1101. default:
  1102. out.write(ch);
  1103. break;
  1104. }
  1105. }
  1106. }
  1107. /**
  1108. * ???????????????????????
  1109. */
  1110. public static String getFirstLetter(String chinese) {
  1111. /**
  1112. * ???
  1113. */
  1114. final int[] li_SecPosValue = {1601, 1637, 1833, 2078, 2274, 2302,
  1115. 2433, 2594, 2787, 3106, 3212, 3472, 3635, 3722, 3730, 3858,
  1116. 4027, 4086, 4390, 4558, 4684, 4925, 5249, 5590};
  1117. final String[] lc_FirstLetter = {"A", "B", "C", "D", "E", "F", "G",
  1118. "H", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",
  1119. "W", "X", "Y", "Z"};
  1120. if (chinese == null || chinese.trim().length() == 0) {
  1121. return "";
  1122. }
  1123. chinese = conversionStr(chinese, "GB2312", "ISO8859-1");
  1124. if (chinese.length() > 1) { // ?��?????????
  1125. int li_SectorCode = (int) chinese.charAt(0); // ????????
  1126. int li_PositionCode = (int) chinese.charAt(1); // ????��??
  1127. li_SectorCode = li_SectorCode - 160;
  1128. li_PositionCode = li_PositionCode - 160;
  1129. int li_SecPosCode = li_SectorCode * 100 + li_PositionCode;// ??????��??
  1130. if (li_SecPosCode > 1600 && li_SecPosCode < 5590) {
  1131. for (int i = 0; i < 23; i++) {
  1132. if (li_SecPosCode >= li_SecPosValue[i]
  1133. && li_SecPosCode < li_SecPosValue[i + 1]) {
  1134. chinese = lc_FirstLetter[i];
  1135. break;
  1136. }
  1137. }
  1138. } else {
  1139. chinese = conversionStr(chinese, "ISO8859-1", "GB2312");
  1140. chinese = chinese.substring(0, 1);
  1141. }
  1142. }
  1143. return chinese;
  1144. }
  1145. private static String conversionStr(String str, String charsetName,
  1146. String toCharsetName) {
  1147. try {
  1148. str = new String(str.getBytes(charsetName), toCharsetName);
  1149. } catch (UnsupportedEncodingException ex) {
  1150. System.out.println("????????????????" + ex.getMessage());
  1151. }
  1152. return str;
  1153. }
  1154. /**
  1155. * ????????????
  1156. *
  1157. * @param html
  1158. * @return
  1159. */
  1160. public static String checkStr(String html) {
  1161. try {
  1162. html = html.replaceAll("\r", "");
  1163. html = html.replaceAll("\n", "");
  1164. html = html.replaceAll("\"", "'");
  1165. html = html.replaceAll("\t", " ");
  1166. Pattern p_script;
  1167. Matcher m_script;
  1168. Pattern p_href;
  1169. Matcher m_href;
  1170. Pattern p_a;
  1171. Matcher m_a;
  1172. Pattern p_on;
  1173. Matcher m_on;
  1174. Pattern p_iframe;
  1175. Matcher m_iframe;
  1176. Pattern p_frameset;
  1177. Matcher m_frameset;
  1178. Pattern p_img;
  1179. Matcher m_img;
  1180. Pattern p_p1;
  1181. Matcher m_p1;
  1182. Pattern p_p2;
  1183. Matcher m_p2;
  1184. String stript_str = "<script[\\s\\S]+</script *>";
  1185. String href_str = " href *= *[\\s\\S]*script *:";
  1186. String on_str = " on[\\s\\S]*=";
  1187. String iframe_str = "<iframe[\\s\\S]+</iframe *>";
  1188. String frameset_str = "<frameset[\\s\\S]+</frameset *>";
  1189. String a_str = "<a ([^>])*>.*?</a([^>])*>";
  1190. //String img_str = "\\<img[^\\>]+\\>";
  1191. String p_str1 = "</p>";
  1192. String p_str2 = "<p>";
  1193. p_script = Pattern.compile(stript_str, Pattern.CASE_INSENSITIVE);
  1194. m_script = p_script.matcher(html);
  1195. html = m_script.replaceAll(""); // ????script???
  1196. p_href = Pattern.compile(href_str, Pattern.CASE_INSENSITIVE);
  1197. m_href = p_href.matcher(html);
  1198. html = m_href.replaceAll(""); // ????script???
  1199. p_a = Pattern.compile(a_str, Pattern.CASE_INSENSITIVE);
  1200. m_a = p_a.matcher(html);
  1201. html = m_a.replaceAll(""); // ????script???
  1202. p_on = Pattern.compile(on_str, Pattern.CASE_INSENSITIVE);
  1203. m_on = p_on.matcher(html);
  1204. html = m_on.replaceAll(""); // ????script???
  1205. p_iframe = Pattern.compile(iframe_str, Pattern.CASE_INSENSITIVE);
  1206. m_iframe = p_iframe.matcher(html);
  1207. html = m_iframe.replaceAll(""); // ????script???
  1208. p_frameset = Pattern
  1209. .compile(frameset_str, Pattern.CASE_INSENSITIVE);
  1210. m_frameset = p_frameset.matcher(html);
  1211. html = m_frameset.replaceAll(""); // ????script???
  1212. // p_img = Pattern.compile(img_str, Pattern.CASE_INSENSITIVE);
  1213. // m_img = p_img.matcher(html);
  1214. // html = m_img.replaceAll(""); // ????script???
  1215. p_p1 = Pattern.compile(p_str1, Pattern.CASE_INSENSITIVE);
  1216. m_p1 = p_p1.matcher(html);
  1217. html = m_p1.replaceAll(""); // ????script???
  1218. p_p2 = Pattern.compile(p_str2, Pattern.CASE_INSENSITIVE);
  1219. m_p2 = p_p2.matcher(html);
  1220. html = m_p2.replaceAll(""); // ????script???
  1221. } catch (Exception e) {
  1222. System.err.println("Html2Text: " + e.getMessage());
  1223. }
  1224. return html;
  1225. }
  1226. public static String substr(String value, int maxlength, String postfix) {
  1227. int k = 0;
  1228. int l = 0;
  1229. for (int i = 0; i < value.length() && maxlength > l * 2 + k; i++) {
  1230. if (value.charAt(i) > '\200') {
  1231. l++;
  1232. } else {
  1233. k++;
  1234. }
  1235. }
  1236. // value????????????????????
  1237. if (l + k >= value.length()) {
  1238. return value;
  1239. } else if (maxlength >= l * 2 + k && l + k > 0) {
  1240. value = value.substring(0, l + k);
  1241. } else if (l + k > 0) {
  1242. value = value.substring(0, (l + k) - 1);
  1243. } else {
  1244. return value;
  1245. }
  1246. // ????????????????????????????????????????
  1247. if (!StringUtils.isEmpty(postfix)) {
  1248. value += postfix;
  1249. }
  1250. return value;
  1251. }
  1252. /**
  1253. * ***************************************************** ??
  1254. * ??????��??????????null???????????????????? ????????param Content:???????????? ????????? ??
  1255. * ?????????????null???????????????????? <p/> ??��?????20051220 ???????
  1256. * ******************************************************
  1257. */
  1258. public String nullToSpace(String Content) {
  1259. if (Content == null) {
  1260. Content = "";
  1261. }
  1262. return Content;
  1263. }
  1264. /**
  1265. * ***************************************************** ??
  1266. * ?????GBK????????ISO8859_1???? ????????param strvalue ??????????????? ????????? ?? ???return
  1267. * String ????????????? ???????
  1268. * ******************************************************
  1269. */
  1270. public String GBK2ISO(String strvalue) throws Exception {
  1271. try {
  1272. if (strvalue == null)
  1273. return null;
  1274. else {
  1275. strvalue = new String(strvalue.getBytes("GBK"), "ISO8859_1");
  1276. return strvalue;
  1277. }
  1278. } catch (Exception e) {
  1279. return null;
  1280. }
  1281. }
  1282. /**
  1283. * 去除换行符
  1284. * @param str
  1285. * @return
  1286. */
  1287. public static String replaceBlank(String str) {
  1288. String dest = "";
  1289. if (str!=null) {
  1290. Pattern p = Pattern.compile("\\s*|\t|\r|\n");
  1291. Matcher m = p.matcher(str);
  1292. dest = m.replaceAll("");
  1293. }
  1294. return dest;
  1295. }
  1296. /**
  1297. * 生成随机
  1298. * @return
  1299. */
  1300. private String getRandomIntStr(){
  1301. Random rand = new Random();
  1302. int i = rand.nextInt(); //int范围类的随机数
  1303. i = rand.nextInt(100); //生成0-100以内的随机数
  1304. i = (int)(Math.random() * 100000000); //0-100以内的随机数,用Matn.random()方式
  1305. return String.valueOf(i);
  1306. }
  1307. }