Alex Rivera | Logout

Reverse of String.Format?

Asked 2009-10-02T20:59:14.610
15

Possible Duplicate:
Parsing formatted string.

How can I use a String.Format format and transform its output to its inputs?

For example:

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".

I know I can use regular expressions to do this, but I would like to use the same format string so I only need to maintain one line of code instead of two.

Edit
Report

1 Answer

1

Here is some code from someone attempting a Scanf equivalent in C#:

http://www.codeproject.com/KB/recipes/csscanf.aspx

answered 2009-10-02T21:07:23.620

Your Answer