Split a separated string into hierarchy using c# and linq

后端 未结 4 1459
粉色の甜心
粉色の甜心 2021-02-14 23:28

I have string separated by dot (\'.\') characters that represents a hierarchy:

string source = \"Class1.StructA.StructB.StructC.FieldA\";

How c

4条回答
  •  暖寄归人
    2021-02-14 23:54

    Shlemiel the painter approach is better than the "super Shlemiel" string.Join in this case.

            const char DELIMITER = '.';
    
            string soFar = "";
            List result = source.Split(DELIMITER).Select(s =>
            {
                if (soFar != "") { soFar += DELIMITER; };
                soFar += s;
                return soFar;
            }).ToList();
    

提交回复
热议问题