我有一个类似以下的字符串:
[Testing.User]|Info:([Testing.Info]|Name:([System.String]|Matt)|Age:([System.Int32]|21))|Description:([System.String]|This is some description)
你可以把它看作这棵树:
- [Testing.User]
- Info
- [Testing.Info]
- Name
- [System.String]
- Matt
- Age
- [System.Int32]
- 21
- Description
- [System.String]
- This is some description
正如您所看到的,它是一个类Testing.User
的字符串序列化/表示。
我希望能够执行拆分操作并在生成的数组中得到以下元素:
[0] = [Testing.User]
[1] = Info:([Testing.Info]|Name:([System.String]|Matt)|Age:([System.Int32]|21))
[2] = Description:([System.String]|This is some description)
我不能使用 |
分割,因为那样会导致:
[0] = [Testing.User]
[1] = Info:([Testing.Info]
[2] = Name:([System.String]
[3] = Matt)
[4] = Age:([System.Int32]
[5] = 21))
[6] = Description:([System.String]
[7] = This is some description)
我该如何得到我期望的结果?
我对正则表达式不是很熟悉,但我知道在这种情况下它是一个非常可行的解决方案。
Testing.User
的序列化编写反序列化器吗?如果不是,是否可以找到Testing.User
的反序列化器并进行自己的重新工程?上面建议将其序列化为另一种格式,如果你/你的团队能够决定切换序列化库,我强烈建议这样做,尤其是如果它是定制的。在当今时代,序列化不应该需要重新开发。 :) - h.j.k.