Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从C#中的字符串中获取多部分子字符串?_C#_String_Substring - Fatal编程技术网

如何从C#中的字符串中获取多部分子字符串?

如何从C#中的字符串中获取多部分子字符串?,c#,string,substring,C#,String,Substring,我正在尝试获取字符串的多个部分作为我的项目“它是fql的一部分”的新字符串,我有以下字符串示例: {"data": [{"text":"how can you get in"},{"text": "this is amazing..."},{"text": "this is another example"}, {"text":"let, this one be the last example and thanks you..."}]} 我想获得新字符串,如下所示: how can you

我正在尝试获取字符串的多个部分作为我的项目“它是fql的一部分”的新字符串,我有以下字符串示例:

{"data": [{"text":"how can you get in"},{"text": "this is amazing..."},{"text": "this is another example"}, {"text":"let, this one be the last example and thanks you..."}]}
我想获得新字符串,如下所示:

how can you get in this is amazing this is another example let this one be the last example and thanks you
另一个例子:

{"data": [{"text":"how can you get in"}]}
新字符串:

how can you get in
另一个:

{"data": []}
新字符串:此字符串的新字符串应为空。

注:以上示例可以是任何尺寸和长度

谢谢。

使用


请展示您的代码并解释您迄今为止所做的尝试。第一步是将此字符串解析为Json。查看优秀的库。获取一个JSON解析器,让它为您构建一个对象,循环字符串结果并构建您的字符串。任意大小和长度?哇!无论如何,这看起来像JSON。找到一个合适的库?到目前为止,我无法解决这个问题,因为它的长度不同,但我可以使用:var stringArray=text.Split(新字符[]{',',',':','-','“','”,'(','),'[',']','{','}','\n','\t',';',''''''''''''''.'.'/');
var anon = new { data = new[] { new { text = "" } } };
var obj = JsonConvert.DeserializeAnonymousType(json, anon);
var text = String.Join(" ", obj.data.Select(x=>x.text));
var jobj = JObject.Parse(json);
var text = String.Join(" ", jobj["data"].Select(x=>x["text"]));