嗨我有一个来自XML节点的字符串,我需要拆分字符串并在一个字符串中获取“filename =”值,而在其他字符串中的所有基于block的块都能够解码并创建文件
我正在使用Split(“\ n”)但是为每一行创建了一行,这不是我需要的。任何想法?
<Attachment>
--boundaryfIudow==
Content-Type: application/octet-stream; name="IERL4-12-61.pdf"
Content-Disposition: attachment; name="IERL4-12-61.pdf";
filename="IERL4-12-61.pdf"
Content-Transfer-Encoding: base64
JVBERi0xLjUNJeLjz9MNCjI4MzQgMCBvYmoNPDwvTGluZWFyaXplZCAxL0wgMTAxNTkyOS9PIDI4
MzcvRSAxMDIyOTMvTiA0Mi9UIDEwMTUxMjkvSCBbIDU4MiA1MDZdPj4NZW5kb2JqDSAgICAgICAg
DQoyODU1IDAgb2JqDTw8L0RlY29kZVBhcm1zPDwvQ29sdW1ucyA1L1ByZWRpY3RvciAxMj4+L0Zp
bHRlci9GbGF0ZURlY29kZS9JRFs8QTlCNjc4ODAwODkwODg0QjgyQURCRDk5N0U4OERERTY+PERD
RDYyNDA0OTNDQUUyNDE5MjkwNzc4OEMyMUE1MEEyPl0vSW5kZXhbMjgzNCA3MF0vSW5mbyAyODMz
IDAgUi9MZW5ndGggMTEwL1ByZXYgMTAxNTEzMC9Sb290IDI4MzUgMCBSL1NpemUgMjkwNC9UeXBl
L1hSZWYvV1sxIDMgMV0+PnN0cmVhbQ0KaN5iYmRgEGBgYmBgMQCRDLtBJKMZmNwCIll3gkhmQbAI
WA3LOjAJES8Gs0+ASUkQyTQJzJYDy64AkYaNQJKR6xGIrSIDNucVmBQFkv9LWBiYGBm4F4FtZ2Ac
LKTAy0Hhkv8M3xVeAQQYAET0ENYNCmVuZHN0cmVhbQ1lbmRvYmoNc3RhcnR4cmVmDQowDQolJUVP
Rg0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgIA0KMjkwMyAwIG9iag08PC9DIDUzNS9GaWx0ZXIvRmxhdGVEZWNvZGUvSSA1NTcv
TGVuZ3RoIDQxMC9PIDUxOS9TIDQzMz4+c3RyZWFtDQpo3mJgYGBiYGA2Z2BhYODLYRBkQABBBmYG
VqA4xwcGBgETZ0MGBgUk2b1/mCIbzigELuC7wX2DxYbVfvNGh0NSr/TEfzImhL4R/iPyiZG1tfvQ
LkU/h2iOoBKmByJ7WNNZ9RlzHCccSN6QeENrmoAnZ0CbGVOdY6HClA43HgU3wZtMx4Am79RUzt0e
mxd2txRI7o7dAhRid/aWkmV3vBQly9soN0PWxaqjVOCVFU+JxAujni8S7UE9h1e0B/ItdngVOAMo
oXjFeaVbIpQASaz2Zg/jW50FJNbIJl2/kLvg0XW+jdntYSAicquJzK0GxowG1owGBgbRBrYGwQYO
Bihi7mBoYOoAMTsYJCBiHkAcgWCCcAMrUAlLB4MGmM8CUkq70AGCDAZu+UJwBDEwSINFXgHZqQyf
D7g8YEkQU+C2YRViusc4vUGLIa1B+2HNHuUHbilAVaKrlzZIBkxmrPRg+BlyXyiIIYCBv+HAA4ih
3GoMjF1lQAYjMDmoAukiBr4rRhAbpqXDo72fgb8qF6KK4TNAgAEAW6qi8w0KZW5kc3RyZWFtDWVu
ZG9iag0yODM1IDAgb2JqDTw8L0xhbmcoZW4tVVMpL01hcmtJbmZvPDwvTWFya2VkIHRydWU+Pi9N
ZXRhZGF0YSAxNDEgMCBSL09wZW5BY3Rpb24gMjgzNiAwIFIvT3V0bGluZXMgMjg4MCAwIFIvUGFn
--boundaryfIudow==--
</Attachment>
答案 0 :(得分:1)
你去(src是你的源字符串):
var split = src.Split('\n').Select(p => p.Trim()).ToList();
var filename = split.First(p => p.StartsWith("filename="));
filename = filename.Substring(10, filename.Length - 11);
var base64 = split[split.Count - 2];
答案 1 :(得分:0)
如果您已有XMLNode,请使用它。 将其解析为元素。
XmlElement attachment = (XmlElement)node;
var filename = attachment.GetAttribute("filename").FirstOrDefault();