2

So, from my understanding, most Asian cultures have family names before given names.

Say I have string firstName = "Andy" string surName = "Peterson"

based on the locale, I want to present his name either as Andy Peterson and Petersen Andy.

Are there any build-in methods inside C#? I was thinking along the line of string.format("Andy", "Peterson", Culture.Info("en-GB")).

Liselej
  • 23
  • 1
  • 5
  • 3
    No, nothing like that exists in the .net framework. You would have to create your own format rules for a custom `Name` or `Person` type. See also [IFormattable](https://learn.microsoft.com/en-us/dotnet/api/system.iformattable?view=netframework-4.7.1) and [IFormatProvider](https://learn.microsoft.com/en-us/dotnet/api/system.iformatprovider?view=netframework-4.7.1) – Igor Oct 29 '17 at 10:36
  • Even within a given culture, rules may depend on how formal the context is. Most of MS own implementations force you decide between those two options and stick with it throughout the application. – Filburt Oct 29 '17 at 10:51
  • @SAkbari and other close-voters: How in the world is this too broad? The OP is simply asking whether something equivalent to locale-specific number, date, or time formatting exists for names. – O. R. Mapper Oct 30 '17 at 06:59
  • @Filburt: "Even within a given culture, rules may depend on how formal the context is." - interestingly, the same could be said about date and time, and yet culture-specific date and time formatting are built into .NET (and many other frameworks). – O. R. Mapper Oct 30 '17 at 07:00
  • @O.R.Mapper Got any reference for that or did you just invent first name terms for months? Abbreviations for date parts are something fundamentally different from the social context present in addressing persons. – Filburt Oct 31 '17 at 21:07
  • @Filburt: I am referring to e.g. expressing time in formal ("four thirty") vs. informal ("half past four") ways. No one's talking about abbreviations here, the OP was just asking about the ordering of given names/surnames. – O. R. Mapper Oct 31 '17 at 23:31

1 Answers1

0

Obtain person full name with String.Format, while storing the format string in the Resources. Resources are culture-specific, and you'll be able to define a different format string per each culture you support.

So if you create a string resource named for example PersonFullNameFormat, you can define it as "{0} {1}" for en-US and "{1} {0}" for ru-RU. Then you can obtain person full name as follows:

var fullName = string.Format(Resources.PersonFullNameFormat, firstName, lastName);

By default, Resources will return values based on Thread.CurrentThread.CurrentUICulture. Initially, it matches selected culture in the OS, but you can override it by setting Thread.CurrentThread.CurrentUICulture to the culture you want:

Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en-GB");

For more info, see:

felix-b
  • 8,178
  • 1
  • 26
  • 36