C# 在c中拆分长字符串#

C# 在c中拆分长字符串#,c#,string,C#,String,我有这个字符串,我需要将它拆分为多个方向 Pending order Sell EUR/USD Price 1.0899 Take profit at 1.0872 Stop loss at 1.0922 From 23:39 18-01-2016 GMT Till 03:39 19-01-2016 GMT 这是我需要拆分的完整字符串 string SellorBuy = "Sell"; string Price = "1.0889"; string Profit = "1.0872"; s

我有这个字符串,我需要将它拆分为多个方向

Pending order
Sell EUR/USD
Price 1.0899
Take profit  at 1.0872
Stop loss at 1.0922
From 23:39 18-01-2016 GMT Till 03:39 19-01-2016 GMT
这是我需要拆分的完整字符串

string SellorBuy = "Sell";
string Price = "1.0889";
string Profit = "1.0872";
string StopLoss = "1.0922";
数字每次都不同,但我仍然需要将它们拆分为自己的字符串。我不知道该怎么办。任何帮助都将不胜感激

我试过的

string message = messager.TextBody;
message.Replace(Environment.NewLine, "|");
string[] Spliter;
char delimiter = '|';
Spliter = message.Split(delimiter);

它似乎没有向其中添加“|”。

在换行符上拆分字符串,然后根据该行的第一个单词处理每一行。有关在换行符上拆分的详细信息,请单击此处


上面的代码实际上只是为了让您开始。您可能应该创建一个名为
PendingOrder
的类,该类具有
Price
Price
等的强类型属性(例如,对数字而不是字符串使用
float
decimal
)并通过构造函数传入原始文本以填充属性。

考虑使用
System.text.RegularExpressions
这正是我想要的。
// Split the string on newlines
string[] lines = theText.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);

// Process each line
foreach(var line in lines){
  var words = line.Split(' ');
  var firstWord = parts[0];

  switch (firstWord){
    case "Price":
      Price = words[1];
      break;
    case "Take":
      Profit = words[words.Length - 1];
      break;
    // etc
  }
}