Today, while looking at the source code, record the learning of the small knowledge.
One, thestring.split method has 6 overloaded functions:
1) Public string[] Split (params char[] separator)
2) public string[] Split (char[] separator, int count)
3) Public string[] Split (char[] separator, stringsplitoptions options)
4) Public string[] Split (string[] separator, stringsplitoptions options)
5) Public string[] Split (char[] separator, int count, stringsplitoptions options)
6) Public string[] Split (string[] separator, int count, stringsplitoptions options)
Below we have some examples to illustrate how to use (the following string words = "1,2.3,,4";):
1. Public string[] Split (params char[] separator)
return value:
Type: System. String[]
separator. ' Data-guid= "7b28a9466989f487697b9306b7388e52" > An array whose elements contain substrings in this instance, separated by one or more characters in the separator . For more information, see the Remarks section.
string[] split = words. Split (new char[] {', '});//return: {"1", "2.3", "", "4"}
string[] split = words. Split (new char[] {', ', '. '}); /return: {"1", "2", "3", "", "4"}
2. Public string[] Split (char[] separator, int count)
string[] split = words. Split (new char[] {', ', '. '}, 2);//return: {"1", "2.3,,4"}
string[] split = words. Split (new char[] {', ', '. '}, 6);//return: {"1", "2", "3", "", "4"}
3. Public string[] Split (char[] separator, stringsplitoptions options)
string[] split = words. Split (new char[] {', ', '. '}, stringsplitoptions.removeemptyentries);//return: {"1", "2", "3", "4"} do not preserve empty elements
string[] split = words. Split (new char[] {', ', '. '}, Stringsplitoptions.none);//return: {"1", "2", "3", "", "4"} Leave empty elements
4. Public string[] Split (string[] separator, stringsplitoptions options)
string[] split = words. Split (new string[] {",", "."}, stringsplitoptions.removeemptyentries);//return: {"1", "2", "3", "4"} do not preserve empty elements
string[] split = words. Split (new string[] {",", "."}, Stringsplitoptions.none);//return: {"1", "2", "3", "", "4"} Leave empty elements
5. Public string[] Split (char[] separator, int count, stringsplitoptions options)
string[] split = words. Split (new char[] {', ', '. '}, 2, stringsplitoptions.removeemptyentries);//return: {"1", "2.3,,4"} does not preserve empty elements
string[] split = words. Split (new char[] {', ', '. '}, 6, stringsplitoptions.none);//return: {"1", "2", "3", "", "4"} Leave empty elements
6. Public string[] Split (string[] separator, int count, stringsplitoptions options)
string[] split = words. Split (new string[] {",", "."}, 2, stringsplitoptions.removeemptyentries);//return: {"1", "2.3,,4"} does not preserve empty elements
string[] split = words. Split (new string[] {",", "."}, 6, stringsplitoptions.none);//return: {"1", "2", "3", "", "4"} Leave empty elements
Note that there is no overloaded function public string[] Split (string[] separator), so we cannot use Words.split (",") like vb.net, and only use words. Split (', ')! A lot of people are wondering why you can change the double quotes to single quotes? Look at the overloaded function above. You know the answer, ^_^.
Second, json.stringify function
Converts JavaScript into a JavaScript Object notation (JSON) string.
Json.stringify (value [, Replacer] [, space])
Converts a JavaScript value to a JavaScript Object Notation (JSON) string.
Parameters:
-
-
Value
-
-
Required. A JavaScript value, usually an object or array, to is converted.
-
-
Replacer
-
-
Optional. A function or array that transforms the results.
If replacer is a function, json.stringify calls the function, passing in the key and value of each Membe R. The return value is used instead of the original value. If the function returns undefined, the member is excluded. The key for the root object was an empty string: "".
If replacer is a array, only members with key values in the array would be converted. The order in which the converted is the same as the order of the "the" in the array. The replacer array is ignored when the value argument was also an array.
-
-
Space
-
-
Optional. Adds indentation, white space, and line break characters to the Return-value JSON text to make it easier to read.
If space is omitted, the Return-value text is generated without any extra white space.
If Space is a number, the Return-value text was indented with the specified number of white spaces at each level. If space is greater than, the text is indented spaces.
If Space is a non-empty string, such as ' \ t ', the Return-value text is indented with the characters in the string At each level.
If Space is a string which is longer than characters, the first ten characters is use.
Example:
var contact = new Object (); contact.firstname = "Jesper"; contact.surname = "Aaberg"; contact.phone = ["555-0100", "555-0120 "];var memberfilter = new Array (); memberfilter[0] =" surname "; memberfilter[1] =" Phone "; var jsontext = Json.stringify (con Tact, MemberFilter, "\ T");d Ocument.write (Jsontext),//Output://{"surname": "Aaberg", "Phone": ["555-0100", "555-0120" ] }
Iii. Methods of Deserializeobject
-
public Object deserializeobject (string input)
parameters
- input
-
type: System . String
JSON string to be deserialized.
return value type: System . Object
deserialized object.