开发者

Winforms C# change string text order

开发者 https://www.devze.com 2023-01-12 23:37 出处:网络
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 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);
0

精彩评论

暂无评论...
验证码 换一张
取 消