List of usage examples for java.lang String replaceAll
public String replaceAll(String regex, String replacement)
From source file:Main.java
public static void main(String[] args) { // \\b to get \b inside the string literal. String regex = "\\bJava\\b"; String replacementStr = "XML"; String inputStr = "Java and Javascript"; String newStr = inputStr.replaceAll(regex, replacementStr); System.out.println("Regular Expression: " + regex); System.out.println("Input String: " + inputStr); System.out.println("Replacement String: " + replacementStr); System.out.println("New String: " + newStr); }
From source file:Main.java
public static void main(String args[]) { String str = "This is a test from java2s.com."; System.out.println(str.replaceAll("is", "are")); }
From source file:Main.java
public static void main(String[] args) { String temp = "<NOUN>Nitin<NOUN> <NOUN>test<NOUN>"; String finalString = "this is a test"; StringTokenizer x = new StringTokenizer(temp, " "); while (x.hasMoreTokens()) { String token = x.nextToken(); String findword = token.replaceAll("<NOUN>", ""); String findword1 = findword.replaceAll("</NOUN>", ""); String modifiedString = finalString.replaceFirst(findword1, "<NOUN>" + findword1 + "</NOUN>"); finalString = modifiedString;//w ww . j a v a 2 s . c o m } System.out.println(finalString); }
From source file:Main.java
public static void main(String[] args) { String a = "this is a test"; System.out.println("Input String is :\n" + a); String b = a.replaceAll("\\s+", ""); System.out.println("\nOutput String is :\n" + b); }
From source file:com.ywh.train.Test.java
public static void main(String[] args) throws Exception { List<NameValuePair> parameters = new ArrayList<NameValuePair>(); parameters.add(new BasicNameValuePair("includeStudent", "00")); parameters.add(new BasicNameValuePair("orderRequest.from_station_telecode", "SHH")); parameters.add(new BasicNameValuePair("orderRequest.start_time_str", "00:00--24:00")); parameters.add(new BasicNameValuePair("orderRequest.to_station_telecode", "CSQ")); parameters.add(new BasicNameValuePair("orderRequest.train_date", "2011-11-24")); parameters.add(new BasicNameValuePair("orderRequest.train_no", "")); parameters.add(new BasicNameValuePair("seatTypeAndNum", "")); parameters.add(new BasicNameValuePair("trainClass", "QB#D#Z#T#K#QT#")); parameters.add(new BasicNameValuePair("trainPassType", "QB")); String responseBody = "0,<span id='id_5l0000D10502' class='base_txtdiv' onmouseover=javascript:onStopHover('5l0000D10502#AOH#CSQ') onmouseout='onStopOut()'>D105</span>,<img src='/otsweb/images/tips/first.gif'> <br> 09:08,<img src='/otsweb/images/tips/last.gif'> <br> 18:21,09:13,--,--,<font color='darkgray'></font>,<font color='#008800'></font>,--,--,--,--,--,--,--,<input type='button' class='yuding_u' onmousemove=this.className='yuding_u_over' onmousedown=this.className='yuding_u_down' onmouseout=this.className='yuding_u' onclick=javascript:getSelected('D105#553#09:08#5l0000D10502#AOH#CSQ') value=''></input>," + "<span id='id_5l0000D10502' class='base_txtdiv' onmouseover=javascript:onStopHover('5l0000D10502#EPH#PXG') onmouseout='onStopOut()'>D105</span>, ? <br> 09:38, ?? <br> 17:09,07:31,--,--,<font color='darkgray'></font>,<font color='darkgray'></font>,--,--,--,--,--,--,--,<input type='button' class='yuding_x' value=''></input>"; List<TrainQueryInfo> tqis = Util.parserQueryInfo(responseBody); for (TrainQueryInfo tqi : tqis) { System.out.println(tqi);//from w ww. j av a2 s. c o m } String citys = "@bji||BJP|0@bjn|?|VNP|1@bjx||BXP|2@cqb|?|CUW|3@sha||SHH|4@shn|?|SNH|5@shq||AOH|6@shx||SXH|7@tji||TJP|8@tjn|?|TIP|9@tjx||TXP|10@cch||CCT|11@cdd|?|ICW|12@cdu|?|CDW|13@csh||CSQ|14@csn|?|CWQ|15@fzh|?|FZS|16@fzn|??|FYS|17@gzb||GBQ|18@gzd||GGQ|19@gzh||GZQ|20@gzn|?|IZQ|21@heb||HBB|22@hfe|?|HFH|23@hkd|?|HMQ|24@hko|?|VUQ|25@hzh|?|HZH|26@hzn|??|XHH|27@jna|?|JNK|28@jnd|?|JAK|29@jnx|?|JGK|30@lzh||LZJ|31@nch|?|NCG|32@nji|?|NJH|33@njn|??|NKH|34@sjb||VVP|35@sjz||SJP|36@sya||SYT|37@syb||SBT|38@tyu||TYV|39@wha||WHN|40@xab||EAY|41@xan||XAY|42@zzh||ZZF|43@aya||AYF|44@bbu||BBH|45@bji|?|BJY|46@cna|??|CEH|47@czh||CZH|48@djy||DDW|49@dli||DLT|50@dsq||DQT|51@dzh||RXW|52@fdi|?|FES|53@han||AUH|54@hda||HDP|55@hko|?|HKN|56@hnx|?|EUH|57@hsh||HSP|58@hsh||HSN|59@jan|?|VAG|60@jgs||JGG|61@jhx|?|JBH|62@jji|?|JJG|63@jli|?|JLL|64@jsh||JUH|65@kfe|?|KFF|66@ksn|?|KNH|67@lan||UAH|68@lhe||LON|69@ljy|?|LKP|70@lym||LLF|71@lzh||LZD|72@nbd|?|NVH|73@nch|?|NCW|74@nto|?|NUH|75@pxi|??|PXG|76@pxx||PCW|77@qcs|?|QSW|78@qda|?|QDK|79@qzh||QEH|80@qzh||QYS|81@shg||SHD|82@sni|??|NIW|83@spi||SPT|84@sqi||SQF|85@sra||SRG|86@sya|??|SNN|87@sya||SEQ|88@szh|?|SZN|89@szh|?|SZH|90@szh||SZQ|91@tgu||TGP|92@tli|?|TLT|93@tsb|?|FUP|94@tsh|?|TSP|95@wch||WCN|96@wfd||WDT|97@wna|?|WNY|98@wxi||WXH|99@wys||WAS|100@wzn|?|VRH|101@xch||XCF|102@xhu||EFQ|103@xmb||XKS|104@xme||XMS|105@xxi||XXF|106@xya||XUN|107@xya||XFN|108@xyu||XUG|109@xzh|?|XCH|110@yan||YWY|111@ych|?|AFH|112@ych||YCG|113@yta||YTG|114@ywu||YWH|115@yxi||YON|116@yzh||YLH|117@zbo|?|ZBK|118@zhb|?|ZIQ|119@zji||ZJH|120@zmd||ZDN|121@zzh||ZZQ|122@zzh||ZEK|123@zzx||ZFK|124@aji||ARH|125@atb||ASH|126@bao|?|BWQ|127@bbn|?|BMH|128@bdh||BEP|129@bdi|?|BDP|130@bhs|??|BWH|131@bji||IBQ|132@bji||BLQ|133@cbb|?|CIN|134@cle|?|CLK|135@czb||ESH|136@czh|?|CXH|137@czx||ICQ|138@czx||CBP|139@dan||DAG|140@dgu||DAQ|141@dsh|?|DRQ|142@dtu||RUH|143@dya||DYH|144@dyb||EXH|145@dyd||IAW|146@dyu||EWH|147@dzd||DIP|148@dzh||DXP|149@ezh||ECN|150@fan|?|FAS|151@fdo||FIH|152@fhu||FHH|153@fqi|?|FQS|154@gmi||GMK|155@gqc|?|GAG|156@gyn|?|GYF|157@gzh|?|GNQ|158@hax||HIH|159@hax||VXN|160@hch|??|WKW|161@hgz||IGW|162@hji||HJS|163@hlb||HPD|164@hni|?|HNH|165@hqi||VQH|166@hsb|?|HDY|167@hsh||VCH|168@hsx||HEQ|169@hyd||HVQ|170@hzh||VON|171@jji||JJS|172@jme||JWQ|173@jsb||EGH|174@jsn|?|EAH|175@jxi||JXH|176@jxn|?|EPH|177@jzb||JZK|178@jzh||JZH|179@jzn|?|JOD|180@lbx|??|LPF|181@lch|?|UCK|182@lfa|?|LJP|183@lha||UFH|184@lji||LKS|185@lsh|?|LSG|186@lsh||LIQ|187@lxi||UXP|188@lyo||LMH|189@lyu|?|LVS|190@lyx||LPQ|191@mcb||MBN|192@mcn|?|MNF|193@mla||MHQ|194@mld||MQQ|195@nde|?|NES|196@nha|?|NHH|197@nla|?|NNQ|198@nxb|?|NEH|199@pjb||PBD|200@pti||PTS|201@qfd||QAK|202@qha|?|QYQ|203@qji||INH|204@qsy||QYH|205@qyu||QBQ|206@qzs|?|QZK|207@ran||RAH|208@rch||RCG|209@rgu||RUQ|210@sde||ORQ|211@sfa|?|OLH|212@sgu||SNQ|213@sjn|??|IMH|214@slo||SLQ|215@smn|?|SCF|216@smx||OQH|217@sxi|?|SOH|218@syu||BDH|219@szb||SND|220@szb|?|OHH|221@szd||SRH|222@szq|?|ITH|223@szq|?|KAH|224@tan|?|TID|225@tan||TMK|226@tms||TLS|227@tna|?|TVW|228@txi|?|TCH|229@tzd||TEK|230@tzh|?|TZH|231@wch||WEQ|232@wfa|??|WFK|233@wli||VHH|234@wnb|?|WBY|235@wni|?|WNQ|236@wqi||WWP|237@wxd||WGH|238@wxq||IFH|239@xga|?|XGN|240@xla|?|EAQ|241@xli||XPH|242@xnb|?|XRN|243@xpu||XOS|244@xpu||XIW|245@xta|?|XTP|246@xzd|?|UUH|247@ych||AIH|248@yds|??|YGH|249@yha|?|EVH|250@yji||URH|251@ylw||TWQ|252@ylz|?|YSY|253@yqb||YPP|254@yqi|?|UPH|255@yxi||ACG|256@yya||YYH|257@yyd||YIQ|258@zji||ZDH|259@zjn|?|ZEH|260@zmt||ZOQ|261@zqi||ZTK|262@zsb||ZGQ|263@zsh||ZSQ|264@zzx||ZAQ|265"; String city[] = citys.split("@"); System.out.println("---------start--------"); for (String tmp : city) { System.out.println(tmp); } System.out.println("---------end--------"); //String test = "? ? ?? ? ? ? ? --> ?? ??? : 260.0()--> ? Sat Nov 26 14:04:16 CST 2011 1 ? ?? ? ? Mon Nov 28 00:00:00 CST 2011 D105 Thu Jan 01 09:08:00 CST 1970 02 052 ?, 260.0 ? --> --> ??"; String test = "1 vxv"; System.out.println(test.replaceAll("\\s", "")); }
From source file:sample.jetty.SampleJettyApplication.java
public static void main(String[] args) throws Exception { InputStream inputstream = null; try {// ww w . j a v a 2 s. c o m Properties pro = new Properties(); //????? URL url = org.springframework.util.ResourceUtils.getURL("classpath:MySql_general.properties"); inputstream = url.openStream(); pro.load(inputstream); //new EmbedMySqlServer(pro).startup(); String dbPath = (new File("")).getAbsolutePath() + "/db/"; dbPath = dbPath.replaceAll("\\\\", "/"); //??? EmbedMySqlServer mysqldbServer = new EmbedMySqlServer(pro, dbPath /*"C:\\gfworklog\\db\\"*/); SampleJettyApplication.MAIN_THREAD_LOCAL.put("embedMysqlServer", mysqldbServer); mysqldbServer.startup(); } catch (Exception e) { e.printStackTrace(); } finally { try { inputstream.close(); } catch (Exception ex) { } } System.out.println(Thread.currentThread().getName() + " ========================= " + 1 + " ========================="); ConfigurableApplicationContext cac = SpringApplication.run(SampleJettyApplication.class, args); }
From source file:icevaluation.BingAPIAccess.java
public static void main(String[] args) { String searchText = "arts site:wikipedia.org"; searchText = searchText.replaceAll(" ", "%20"); // String accountKey="jTRIJt9d8DR2QT/Z3BJCAvY1BfoXj0zRYgSZ8deqHHo"; String accountKey = "JfeJSA3x6CtsyVai0+KEP0A6CYEUBT8VWhZmm9CS738"; byte[] accountKeyBytes = Base64.encodeBase64((accountKey + ":" + accountKey).getBytes()); String accountKeyEnc = new String(accountKeyBytes); URL url;//from w ww . j ava 2 s. c o m try { url = new URL("https://api.datamarket.azure.com/Bing/Search/v1/Composite?Sources=%27Web%27&Query=%27" + searchText + "%27&$format=JSON"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.setRequestProperty("Authorization", "Basic " + accountKeyEnc); BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); StringBuilder sb = new StringBuilder(); String output; System.out.println("Output from Server .... \n"); //write json to string sb int c = 0; if ((output = br.readLine()) != null) { System.out.println("Output is: " + output); sb.append(output); c++; //System.out.println("C:"+c); } conn.disconnect(); //find webtotal among output int find = sb.indexOf("\"WebTotal\":\""); int startindex = find + 12; System.out.println("Find: " + find); int lastindex = sb.indexOf("\",\"WebOffset\""); System.out.println(sb.substring(startindex, lastindex)); } catch (MalformedURLException e1) { e1.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { URL url = new URL("http://www.java.com/"); URLConnection urlConnection = url.openConnection(); DataInputStream dis = new DataInputStream(urlConnection.getInputStream()); String html = "", tmp = ""; while ((tmp = dis.readUTF()) != null) { html += " " + tmp; }/*from w w w.j a v a2 s . c om*/ dis.close(); html = html.replaceAll("\\s+", " "); Pattern p = Pattern.compile("<title>(.*?)</title>"); Matcher m = p.matcher(html); while (m.find() == true) { System.out.println(m.group(1)); } }
From source file:MainClass.java
public static void main(String args[]) { String firstString = "This sentence ends in 5 stars *****"; System.out.printf("Original String 1: %s\n", firstString); // replace '*' with '^' firstString = firstString.replaceAll("\\*", "^"); System.out.printf("^ substituted for *: %s\n", firstString); }
From source file:MainClass.java
public static void main(String args[]) { String firstString = "This sentence ends in 5 stars *****"; System.out.printf("Original String 1: %s\n", firstString); // replace 'stars' with 'carets' firstString = firstString.replaceAll("stars", "carets"); System.out.printf("\"carets\" substituted for \"stars\": %s\n", firstString); }