Joe Cartano
Joe Cartano

Reputation: 3037

String.Format and culture

When formatting a string as opposed to a DateTime, does the culture ever come into play? Are there any examples of strings that would be formatted differently with two different cultures?

Upvotes: 3

Views: 780

Answers (4)

to StackOverflow
to StackOverflow

Reputation: 124804

I don't believe so in the current Framework. But if Microsoft ever implements this suggestion on the Connect feedback site, it includes a suggestion to have a format specifier to force upper case:

String.Format("{0:U}", "SomeString") => "SOMESTRING"

Such formatting would be culture-specific.

Upvotes: 3

Jason Down
Jason Down

Reputation: 22191

If you are displaying a string that is stored as a resource it will make a difference if you have separate strings for different cultures (you'd use CultureInfo.CurrentUICulture). For example error messages accessed via a ResourceManager.

Upvotes: 3

Will A
Will A

Reputation: 25018

String.Format("{0}", "This string") - which I believe is what you're implying by your question, is not affected by the culture.

Upvotes: 1

Waqas Raja
Waqas Raja

Reputation: 10870

There are many scenarios when you need culture based formatting.

For example: - Number Format

5.25 in English is written as 5,25 in French

So, if you want to display French formatted number in your program which is in English culture the culture based string format comes into action.

Upvotes: 0

Related Questions