I am new to C# and I get the user's name that is system generated and it comes in the format:
LastName, FirstName
I want to change this to be added to a database
FirstName.LastName
I am totally stuck on how to do开发者_JS百科 this, any help would be great,
If the order always comes as "Lastname, Firstname", the following code should work:
var variableContainingLastNameFirstName = "LastName, FirstName";
var split = variableContainingLastNameFirstName.Split(new char[] {',' });
var firstNamelastName = string.Format("{0}, {1}", split[0], split[1]);
Try this:
string username = "LastName, FirstName";
string[] words = username.Split(new string[]{", "});
string result = words[1] + "." + words[0]; // storing
// for output
Console.WriteLine("{0}.{1}", words[1], words[0]);
Console.WriteLine(result);
精彩评论