Get an acronym from a string in C# using LINQ?

后端 未结 6 1442
傲寒
傲寒 2021-01-18 01:09

Here is how I would write a function to make an acronym in Java style:

    string makeAcronym(string str)
    {
        string result = \"\";
        for (in         


        
6条回答
  •  南笙
    南笙 (楼主)
    2021-01-18 01:44

    You can do this quite nicely using a Regex/Linq combo:

    String
        .Join("",
            Regex
                .Matches("this is a test",@"(?<=^| )\w")
                .Cast()
                .Select(m=>m.Value)
                .ToArray()
        )
    

提交回复
热议问题