如何拆分格式化字符串

本文关键字:格式化 字符串 拆分 何拆分 | 更新日期: 2023-09-27 18:27:05

string text = "try your {{equal|even out|regularize}  out|steady|tied|equal}";

实际上我想拆分外括号内的所有单词({}(。

例如,如果这是字符串:"{{equal|even out|regularize} out|steady|tied|equal}",我希望拆分结果数组是这样的: { 等于, 甚至出来, 规范 外 稳定 拴 等于 }

string text = "try your {{equal|even out|regularize}  out|steady|tied|equal}  {champion|finest|top-quality}";
string1 = "try";
string2 = "your";
string3="{{equal|even out|regularize}  out|steady|tied|equal}";
string4="{champion|finest|top-quality}";

怎么这样分裂...请帮帮我...谢谢!

如何拆分格式化字符串

试试这个:

string text = "try your {{equal|even out|regularize}  out|steady|tied|equal}";
text = text.Remove(0, text.IndexOf('{'));
var array = text.Split('{', '}', '|');
array.ToList().ForEach(item =>
{
      Console.WriteLine(item);
});

输出:

equal
even out
regularize
  out
steady
tied
equal