开发者

Winforms C# change string text order

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜