[\r\n "50f59381aab245e31ff9781a68d7727ea3035fd8",\r\n "63dea0856bb39e575016c4f4c48f10d3d5e269c0",\r\n "6958e834573cc31ece22f489972919095568fa80",\r\n "745ed0558f741f3974bf6ceaaf9de1e36489703d",\r\n "8e7afefa0c19db0e7daf813dbacc1057ee49e01c",\r\n "9b80fe22f97e27a5a6e3c9b6267a5d5623a2c7e3",\r\n "9f043e3ff743d2c51cd22d71a17d6e6975d7810b",\r\n "c6a17769cc166a2c18f5533bf673f1a76e2dbb02",\r\n "c72218b3b2d6f0f397570a6dce5853c0b0499b9d",\r\n "e34bf5fe513759ea88723f1ac2521bd9e1bec3c5",\r\n "fb4152ad15e1a3b12da800ecad2f5d91a67911bf"\r\n]
以上字符串 想把
50f59381aab245e31ff9781a68d7727ea3035fd8
……..
e34bf5fe513759ea88723f1ac2521bd9e1bec3c5
fb4152ad15e1a3b12da800ecad2f5d91a67911bf
等 内容 加到list 集合中
求 高手 告知
解决方案
20
string input = "[\r\n "50f59381aab245e31ff9781a68d7727ea3035fd8",\r\n "63dea0856bb39e575016c4f4c48f10d3d5e269c0",\r\n"6958e834573cc31ece22f489972919095568fa80",\r\n "745ed0558f741f3974bf6ceaaf9de1e36489703d",\r\n "8e7afefa0c19db0e7daf813dbacc1057ee49e01c",\r\n "9b80fe22f97e27a5a6e3c9b6267a5d5623a2c7e3",\r\n "9f043e3ff743d2c51cd22d71a17d6e6975d7810b",\r\n "c6a17769cc166a2c18f5533bf673f1a76e2dbb02",\r\n "c72218b3b2d6f0f397570a6dce5853c0b0499b9d",\r\n "e34bf5fe513759ea88723f1ac2521bd9e1bec3c5",\r\n "fb4152ad15e1a3b12da800ecad2f5d91a67911bf"\r\n]"; List<string> Result = new List<string>(); Regex rg=new Regex("(?<=").+?(?=")"); foreach(Match m in rg.Matches(input)) { Result.Add(m.Value); }
测试通过
20
代码经验证,无误
string s = "[\r\n "50f59381aab245e31ff9781a68d7727ea3035fd8",\r\n "63dea0856bb39e575016c4f4c48f10d3d5e269c0",\r\n "6958e834573cc31ece22f489972919095568fa80",\r\n "745ed0558f741f3974bf6ceaaf9de1e36489703d",\r\n "8e7afefa0c19db0e7daf813dbacc1057ee49e01c",\r\n "9b80fe22f97e27a5a6e3c9b6267a5d5623a2c7e3",\r\n "9f043e3ff743d2c51cd22d71a17d6e6975d7810b",\r\n "c6a17769cc166a2c18f5533bf673f1a76e2dbb02",\r\n "c72218b3b2d6f0f397570a6dce5853c0b0499b9d",\r\n "e34bf5fe513759ea88723f1ac2521bd9e1bec3c5",\r\n "fb4152ad15e1a3b12da800ecad2f5d91a67911bf"\r\n]"; List<string> sss = (List<string>)new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(List<string>)).ReadObject(new MemoryStream(Encoding.Default.GetBytes(s))); foreach (var item in sss) { Console.WriteLine(item); }
结果
50f59381aab245e31ff9781a68d7727ea3035fd8 63dea0856bb39e575016c4f4c48f10d3d5e269c0 6958e834573cc31ece22f489972919095568fa80 745ed0558f741f3974bf6ceaaf9de1e36489703d 8e7afefa0c19db0e7daf813dbacc1057ee49e01c 9b80fe22f97e27a5a6e3c9b6267a5d5623a2c7e3 9f043e3ff743d2c51cd22d71a17d6e6975d7810b c6a17769cc166a2c18f5533bf673f1a76e2dbb02 c72218b3b2d6f0f397570a6dce5853c0b0499b9d e34bf5fe513759ea88723f1ac2521bd9e1bec3c5 fb4152ad15e1a3b12da800ecad2f5d91a67911bf