|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- > 字符串的处理离不开split方法
- - 对单个字符进行分割(注意这里是字符,不是字符串,故只能用单引号‘’)
- ```
- string s=abcdeabcdeabcde;
- string[] sArray=s.Split('c') ;
- foreach(string i in sArray)
- Console.WriteLine(i.ToString());
-
- 输出结果为:ab deab deab de
- ```
- - 对多个字符进行分割
- ```
- string s="abcdeabcdeabcde";
- string[] sArray1=s.Split(new char[3]{'c','d','e'}) ;
- foreach(string i in sArray1)
- Console.WriteLine(i.ToString());
-
- 输出结果为:ab ab ab
- ```
- - 使用正则表达式
- ```
- using System.Text.RegularExpressions;
- string str="aaajsbbbjsccc";
- string[] sArray=Regex.Split(str,"js",RegexOptions.IgnoreCase);
- foreach (string i in sArray) Response.Write(i.ToString());
-
- 输出结果为:aaa bbb ccc
- ```
-
- - 项目中使用到split方法
-
- ```
- model.SceneName = scene.Name.Split(',')[0];
- model.TriggerMode = GetTriggerName(scene.Name.Split(',')[1]);
- ```
- ```
- string[] kg= kaiguanIds.Split(',');
- foreach (var item in kg)
- {
- var scenekaiguan =new SceneKaiGuanItemViewModel();
- var kaiguanId = item.Split('_')[0];
- var kaiguanStatus = item.Split('_')[1];
- }
- [0]第一个元素
- [1]第二个元素
- ```
|