是否有一个等同于.NET“的sscanf()”?
.NET框架给了我们格式方式:
The .NET Framework gives us the Format method:
string s = string.Format("This {0} very {1}.", "is", "funny");
// s is now: "This is very funny."
我想一个格式化恢复功能,是这样的:
I would like an "Unformat" function, something like:
object[] params = string.Unformat("This {0} very {1}.", "This is very funny.");
// params is now: ["is", "funny"]
我知道类似的东西存在于ANSI-C库(的printf VS的scanf )。
问题:是否有在C#中类似的东西。
The question: is there something similiar in C#?
更新:捕获组定期EX pressions不是我所需要的解决方案。它们也是一种方法。我在寻找一个系统,该系统能正常工作双向在一个单一的格式。这是确定要放弃一些功能(如类型和格式的信息)。
Update: Capturing groups with regular expressions are not the solution I need. They are also one way. I'm looking for a system that can work both ways in a single format. It's OK to give up some functionality (like types and formatting info).
有可能是因为解决歧义的问题没有这样的方法,:
There's no such method, probably because of problems resolving ambiguities:
string.Unformat("This {0} very {1}.", "This is very very funny.")
// are the parameters equal to "is" and "very funny", or "is very" and "funny"?
正前pression 捕捉的 是我们对这个问题小组;你可能想看看他们。
Regular expression capturing groups are made for this problem; you may want to look into them.