可能有重复:
解析格式化的字符串。
我如何使用String.Format
格式并将其输出转换为其输入?
例如:
string formatString = "My name is {0}. I have {1} cow(s).";
string s = String.Format(formatString, "strager", 2);
// Call the magic method...
ICollection<string> parts = String.ReverseFormat(formatString, s);
// parts now contains "strager" and "2".
我知道可以使用正则表达式来做这件事,但我希望使用相同的格式字符串,这样我只需要维护一行代码而不是两行。