English 中文(简体)
利用RegEx和C#进行扼杀
原标题:Parse string using RegEx and 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

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.

我认为,如果我在“条码”后宣读所有案文:,这可以成为一种可能的方法,那么任何帮助都会受到高度赞赏。

最佳回答

你们可以使用雷诺威,但既然这样看,你会更好地利用“智者”。 NET to parse that.

JObject o = JObject.Parse(@"{
  ""Stores"": [
    ""Lambton Quay"",
    ""Willis Street""
  ],
  ""Manufacturers"": [
    {
      ""Name"": ""Acme Co"",
      ""Products"": [
        {
          ""Name"": ""Anvil"",
          ""Price"": 50
        }
      ]
    },
    {
      ""Name"": ""Contoso"",
      ""Products"": [
        {
          ""Name"": ""Elbow Grease"",
          ""Price"": 99.95
        },
        {
          ""Name"": ""Headlight Fluid"",
          ""Price"": 4
        }
      ]
    }
  ]
}");

string name = (string)o.SelectToken("Manufacturers[0].Name");
// Acme Co

decimal productPrice = (decimal)o.SelectToken("Manufacturers[0].Products[0].Price");
// 50

string productName = (string)o.SelectToken("Manufacturers[1].Products[0].Name");
// Elbow Grease

。 Json.Net Selected Token

http://json.codeplex.com/“rel=“nofollow” JSON.NET Library。

问题回答

我愿利用C#中的Reex的话说,这就是这样。

MatchCollection matchCtrls = Regex.Matches(pageText, @"Th(.*)e", RegexOptions.Singleline);

If you don t know what the text is going to be specifically then probably something like this

MatchCollection matchCtrls = Regex.Matches(pageText, @"": (.*)", RegexOptions.Singleline);




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签