Is the 1.string object final?
1 String str= "asdfdf"; 2 str.replace ("as", "" "); 3 System.out.println (str); // ASDFDF 4 str=str.replace ("as", "" "); 5 System.out.println (str); // DFDF
2. Cutting of strings
An issue was encountered that gets parameters based on a URL: Enterid = Long.parselong (Target.split ("/") [2]); This is going to deal with the cut string problem This is the case in Splitapi: Public string[] Split (string regex,int limit) splits this string by matching a given regular expression. The array returned by this method contains substrings of this string, each of which is terminated by another substring that matches the given expression, or terminated by the end of the string. The substrings in the array are arranged in the order in which they appear in this string. If the expression does not match any part of the input, then the resulting array has only one element, that is, this string. The limit parameter controls the number of times the pattern is applied and therefore affects the length of the resulting array. If the limit n is greater than 0, the pattern will be applied up to n-1 times, the length of the array will not be greater than N, and the last item of the array will contain all inputs that exceed the last matching delimiter. If n is not positive, then the pattern will be applied as many times as possible, and the array can be any length. If n is 0, then the pattern will be applied as many times as possible, the array can be any length, and the trailing empty string will be discarded. For example, the string "Boo:and:foo" uses these parameters to produce the following results: Regex Limit Results : 2 {"Boo", "And:foo"} : 5 {"Boo", "and", "foo"} :-2 {"Boo", "and", "foo"} o 5 {"B", "", ": And:f", "", ""} o-2 {"B", "", ": And:f", "", ""} o 0 {"B", "", ": And:f"} Public string[] Split (string regex) splits this string based on the match of the given regular expression. the method acts as if the two-argument split method is called with the given expression and the limit parameter. Therefore, the resulting array does not include the trailing empty string. For example, the string "Boo:and:foo" uses these expressions to produce the following results: Regex Results : {"Boo", "and", "foo"} o {"B", "", ": And:f"} Parameters: Regex-bound Regular expression Return: A string array that is determined by the matching of the given regular expression to split this string. Thrown: Patternsyntaxexception-If the syntax of the regular expression is invalid
|
3. Null value for JSON string
Upload code error causes the database address storage problems, there are some empty value, and the end of more than two key value pairs, of course, there is no problem. Poor command of SQL, so chose to use Java processing, update the database.
The data objects that are processed are the following:
1 ' {\ "showimg_1\": \ "/upload/webhome/template/4ddedebb-7615-4686-b27a-b515a6a5a2cc.jpg\", \ "ShowImg_2\" : \ "/upload/webhome/template/2c0806ee-6165-4b95-949d-340ddad18171.jpg\", \ "showimg_3\": \ "/upload/webHome/ Template/35464a57-a987-4e40-91b4-f5b33e343f46.jpg\ ", \" showimg_4\ ": \"/upload/webhome/template/ 9bddbbd6-1ad2-4290-b087-caa26bf93197.jpg\ ", \" showimg_5\ ": \"/upload/webhome/template/ 604b7531-384b-4052-93cb-e5d51182023b.jpg\ ", \" showimg_6\ ": \"/upload/webhome/template/ 4673cf82-fa07-4acc-ac7c-e5c7ef9af687.jpg\ ", \"showimg_7\ ": \" \ ", \" showimg_8\ ":\" \ ", \" Emplate.quickmark\ ": \"/upload/webhome/template/27b4cb88-b3b2-4046-bedd-c4ad92735310.jpg\ ", \" Emplate.img\ ": \"/upload/webhome/template/7949e9eb-eb86-4d54-ab09-1271ea202b2e.jpg\ "} '
The jfinal frame used:
1 /**2 * Processing error data3 */4 Public voidManagesql () {5String sql= "SELECT * from _table";6List<record> list=db.find (SQL);7SetAttr ("Length", List.size ());8 for(inti=0; I<list.size (); i++){9 //Take out a recordTenRecord r=List.get (i); One //Extracting JSON data AString json=r.getstr ("Showimg"); -SetAttr ("old=", JSON); - //Remove the error data from the beginning of the Emplate key the intInd=json.indexof (", \" Emplate "); - if(ind>0){ -Json=json.substring (0, Ind) + "}"; - } +SetAttr ("new=", JSON); - //remove element with value "" +Json=json.replaceall ((<=\\{) \ "\\w+\": \ "\", |,*\ "\\w+\": \ "\") "," "); ASetAttr ("All:" +I,json); at -System.out.println (json+ "========="); - - //Inventory Save Update -R.set ("Showimg", JSON); - inDb.update ("Home_template", R); - to } + - Renderjson (); the}
Some methods of 4.String objects:
Length ()-Return lengths, note and JS in different, JS inside is the length property.
Corresponding length: The length of the array-length;list length-size ();
Some features of string encountered in Java