使用 RegEx 和 C# 解析字符串
我有以下正则表达式 -
string s = "{\"data\": {\"words\": [{\"wordsText\": \"Three Elephants /d
in the jungle\"}]}}";
string[] words = s.Split('\\',':','[',']','{','}','"');
foreach (string word in words)
{
Console.WriteLine(word);
}
哪个输出 -
data
words
wordsText
Three Elephants /d in the jungle
删除输出中前 3 行的最佳方法是什么,以便我只得到最后一行 - 丛林中的三头大象 /d
。
我相信,如果我要写出 "wordsText\":
之后的所有文本,这可能是一种可能的方法,非常感谢任何帮助。
I have the following Regular Expression-
string s = "{\"data\": {\"words\": [{\"wordsText\": \"Three Elephants /d
in the jungle\"}]}}";
string[] words = s.Split('\\',':','[',']','{','}','"');
foreach (string word in words)
{
Console.WriteLine(word);
}
Which outputs-
data
words
wordsText
Three Elephants /d in the jungle
What is the best way to get rid of the first 3 lines in the output so that I only get the last line- Three Elephants /d in the jungle
.
I believe if I were to write out all text after "wordsText\":
this could be a possible method, any help is much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您当然可以使用 RegEx,但由于它看起来像 JSON,您最好使用 JSON.NET 来解析它。
请参阅: Json.Net Select Token
这使用 JSON.NET 库。
You could use RegEx sure, but since that looks like JSON you would be better off using JSON.NET to parse that.
See: Json.Net Select Token
This uses the JSON.NET Library.
我会在 C# 中使用正则表达式,你的表达式会是这样的
如果你不知道文本具体是什么,那么可能是这样的
I would use the Regex in C# your expressions for that would be like this
If you don't know what the text is going to be specifically then probably something like this