今天趁着看源代码的同时,记录学习的小知识。

一、String.Split 方法有6个重载函数:

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)

下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):

1. public string[] Split(params char[] separator)

返回值:

类型:System.String[]
一个数组,其元素包含此实例中的子字符串,这些子字符串由 separator 中的一个或多个字符分隔。 有关更多信息,请参见“备注”一节。 

string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}

2. public string[] Split(char[] separator, int count)

string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}

3. public string[] Split(char[] separator, StringSplitOptions options)

string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素

4. public string[] Split(string[] separator, StringSplitOptions options)

string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素

5. public string[] Split(char[] separator, int count, StringSplitOptions options)

string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素

6. public string[] Split(string[] separator, int count, StringSplitOptions options)

string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素

需要注意的是没有重载函数public string[] Split(string[] separator),所以我们不能像VB.NET那样使用words.Split(","),而只能使用words.Split(',')!很多人都很奇怪为什么把双引号改为单引号就可以了?看了上边的重载函数该知道答案了吧^_^

二、JSON.stringify 函数

将 JavaScript 转换为 JavaScript 对象表示法 (JSON) 字符串。

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 be 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 member. 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 is an empty string: "".

If replacer is an array, only members with key values in the array will be converted. The order in which the members are converted is the same as the order of the keys in the array. The replacer array is ignored when the value argument is 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 is indented with the specified number of white spaces at each level. If space is greater than 10, text is indented 10 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 that is longer than 10 characters, the first 10 characters are 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(contact, memberfilter, "\t");
document.write(jsonText);
// Output:
// { "surname": "Aaberg", "phone": [ "555-0100", "555-0120" ] }

三、DeserializeObject 方法

public Object DeserializeObject(
string input

参数

input
类型:System.String
要进行反序列化的 JSON 字符串。

返回值

类型:System.Object
反序列化的对象。


最新文章

  1. 禁止root用户远程登录
  2. Bootstrap使用心得
  3. 17.1.1.1 Setting the Replication Master Configuration 设置复制的master 配置:
  4. Cmd批处理语法实例
  5. 【Ubuntu 16】源码包安装Apache Httpd
  6. python中的字符串格式化
  7. 小米众筹新品---8H凉感慢回弹记忆绵枕 99元 上手开箱图
  8. Vue学习之路1-集成环境安装
  9. JAVA反射机制及理解
  10. Android Stdio 无法打开模拟器
  11. EDI error
  12. ASP.NET MVC 使用Jquery异步操作JS代码
  13. Centos Firefox中文乱码
  14. typescript handbook 学习笔记2
  15. adb的使用
  16. 在VC++中怎样改变控件间的TAB切换顺序?
  17. hadoop 链接 mysql
  18. HTTP 499 状态码 nginx下 499错误[转]
  19. nginx详细应用
  20. django 保存订单乐观锁的使用

热门文章

  1. localStorage使用总结,页面跳转,保存值
  2. (Spring Boot框架)快速入门
  3. 《转》ceilometer的数据採集机制入门
  4. RVM(ruby version manage)安装指南
  5. Atitit. 悬浮窗口的实现 java swing c# .net c++ js html 的实现
  6. atitit.故障排除--- 当前命令发生了严重错误。应放弃任何可能产生的结果sql server 2008
  7. spring 发布 Jax-Ws Service (一)
  8. win7如何连接蓝牙键盘
  9. udacity android 实践笔记: lesson 4 part b
  10. [内核]procfs和sysfs