-1

嗨,我有一个来自 XML 节点的字符串,我需要拆分字符串并在一个字符串中获取“filename =”值,并在另一个字符串中获取所有 based64 块,以便能够对其进行解码并创建文件。

我正在使用 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>
4

2 回答 2

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];
于 2013-02-01T09:28:01.110 回答
0

如果您已经拥有 XMLNode,请使用它。将其解析为一个元素。

XmlElement attachment = (XmlElement)node; 
var filename = attachment.GetAttribute("filename").FirstOrDefault();
于 2013-02-01T09:40:23.117 回答