.net 3.5 - Named string formatting in C# -



.net 3.5 - Named string formatting in C# -

is there way format string name rather position in c#?

in python, can illustration (shamelessly stolen here):

>>> print '%(language)s has %(#)03d quote types.' % \ {'language': "python", "#": 2} python has 002 quote types.

is there way in c#? instance:

string.format("{some_variable}: {some_other_variable}", ...);

being able using variable name nice, dictionary acceptable too.

update: ended doing this post, it's not pretty. i'll seek out john sheehan's approach, if has other suggestions in meantime, sense free add together them. :)

update 2: john sheehan's approach works pretty well. accepting it.

there no built-in method handling this.

here's 1 method

string mystring = "{foo} {bar} , {yadi} {yada}".inject(o);

here's another

status.text = "{username} lastly logged in @ {lastlogindate}".formatwith(user);

a 3rd improved method partially based on 2 above, phil haack

c# .net-3.5 string-formatting

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -