.net eval() equivalent

Say you have two strings.

String 1: "FormatDateTime((0}, DateFormat.ShortDate)"
String 2: "3/17/2005 1:40:00 AM"

Is it possible to apply the format within string 1 to string 2? For what it's worth, the value will not always contain a date, it should be able to handle anything.

I know that the existing EVAL() function would do what I'm looking for, but I need a .NET 2.0 equivalent. TIA!
RobinsRLAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jason ScolaroCommented:
Hi RobinsRL,

Could you explain this a bit more.. it seems confusing to me.  Do you want what is declared in String 1 to effect String 2's format?  And when you reference Eval(), do you mean the DataBinder.Eval(), which still occurs in .NET 2.0.  Help me understand, please.. ;)

-- Jason
RobinsRLAuthor Commented:
Hi Jason,

Yes, I want the format string contained in string 1 to effect string 2's format.  I can't use the databinder.eval because i want to achieve this in the code-behind.  

If i had these two strings:
String 1: "FormatDateTime((0}, DateFormat.ShortDate)"
String 2: "3/17/2005 1:40:00 AM"

this would be the output:
"3/17/2005"
Jason ScolaroCommented:
RobinsRL,

I guess I'm still confused, because you can still use the Eval() function in code-behind:
Return Eval(string2, string1)

-- Jason
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

RobinsRLAuthor Commented:
No, eval is not available in the .net framework.
Jason ScolaroCommented:
RobinsRL,

I'm not sure why you would say that.. it definitely exists in the .NET Framework.  And any shortcomings that the Eval function has for your scenario, you could always fallback to the DataBinder.Eval() function:

http://quickstart.developerfusion.co.uk/QuickStart/aspnet/doc/data/templates.aspx

-- Jason
RobinsRLAuthor Commented:
Jason,

I need an example of eval() used in a code-behind page, not on a formview, dataview or datagrid.
Jason ScolaroCommented:
RobinsRL,

Another thought came across my mind as well that might work for you better would be the String.Format() method since that's all you really need...

Play around with this:
Dim s1 As String = "String1"
String.Format("YourStringFormat", s1)

http://www.builderau.com.au/architect/dotnet/0,39024710,39177160,00.htm

There is also a Format() method....

You can use the DataBinder.Eval method anywhere in your code-behind... it takes 2 or 3 parameters...

DataBinder.Eval(containerObject, "Expression", "Format")

If I get some time in the morning I'll find you some code examples.

Good luck!
-- Jason

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.