如何将字符串拆分为字符串数组?

时间:2013-10-02 07:16:57

标签: c# string split xps

其实我正在读取我的程序中的xps.file。我的xps文件应该是这样的 enter image description here

我粘贴以下代码

List<string> lData = new List<string>();
        using (XpsDocument xpsDoc = new XpsDocument(fileName, System.IO.FileAccess.Read))
        {
            FixedDocumentSequence docSeq = xpsDoc.GetFixedDocumentSequence();
            Dictionary<string, string> docPageText = new Dictionary<string, string>();
            for (int pageNum = 0; pageNum < docSeq.DocumentPaginator.PageCount; pageNum++)
            {
                DocumentPage docPage = docSeq.DocumentPaginator.GetPage(pageNum);
                foreach (System.Windows.UIElement uie in ((FixedPage)docPage.Visual).Children)
                {
                    if (uie is System.Windows.Documents.Glyphs)
                    {
                        lData.Add(((System.Windows.Documents.Glyphs)uie).UnicodeString);
                    }
                }
            }
        }

通过使用上面的代码,我得到了元素列表。基于此我得到一个用空格

分隔的字符串
            foreach (string elmnt in lData)
        {
            strText += elmnt + " ";
        }

从这个字符串我想拆分它。字符串应该是这样的

LD1089546 LD1089546 LD1089546 ABDLys2HO+ ScreenLysP - LD1089547 LD1089547 LD1089547 ScreenLysP - LD1089548 LD1089548 LD1089548 ScreenLysP - ABDLys2HO+ 
LD1089549 LD1089549 LD1089549 ABDLys2HO+ ScreenLysP - LD1094450 LD1094450 LD1094450 ScreenLysP - ABDLys2HB+ LD1094451 LD1094451 LD1094451 ScreenLysP - ABDLys2HB+ 
LD1094452 LD1094452 LD1094452 ScreenLysP - ABDLys2HO+ LD1094453 LD1094453 LD1094453 ScreenLysP - ABDLys2HA+ LD1094454 LD1094454 LD1094454 ScreenLysP - ABDLys2HB+ 
LD1094455 LD1094455 LD1094455 ScreenLysP - ABDLys2HA+ LD1094456 LD1094456 LD1094456 ScreenLysP - ABDLys2HAB+ LD1094457 LD1094457 LD1094457 ScreenLysP - ABDLys2HO+ 
LD1094458 LD1094458 LD1094458 ABDLys2HAB+ ScreenLysP - LD1094461 LD1094461 LD1094461 ScreenLysP - ABDLys2HB+ LD1094463 LD1094463 LD1094463 ScreenLysP - ABDLys2HXX 
LD1094464 LD1094464 LD1094464 ScreenLysP - ABDLys2HO+ LD1094465 LD1094465 LD1094465 ScreenLysP - ABDLys2HA+ LD1094466 LD1094466 LD1094466 ScreenLysP - ABDLys2HB+ 

我想结果数组应该像这样

LD1089546 LD1089546 LD1089546 ABDLys2HO+ ScreenLysP - 
LD1089547 LD1089547 LD1089547 ScreenLysP - 
LD1089548 LD1089548 LD1089548 ScreenLysP - ABDLys2HO+ 
LD1089549 LD1089549 LD1089549 ABDLys2HO+ ScreenLysP - 
LD1094450 LD1094450 LD1094450 ScreenLysP - ABDLys2HB+ 
LD1094451 LD1094451 LD1094451 ScreenLysP - ABDLys2HB+ 
LD1094452 LD1094452 LD1094452 ScreenLysP - ABDLys2HO+ 
LD1094453 LD1094453 LD1094453 ScreenLysP - ABDLys2HA+ 
LD1094454 LD1094454 LD1094454 ScreenLysP - ABDLys2HB+ 
LD1094455 LD1094455 LD1094455 ScreenLysP - ABDLys2HA+ 
LD1094456 LD1094456 LD1094456 ScreenLysP - ABDLys2HAB+ 
LD1094457 LD1094457 LD1094457 ScreenLysP - ABDLys2HO+ 
LD1094458 LD1094458 LD1094458 ABDLys2HAB+ ScreenLysP - 
LD1094461 LD1094461 LD1094461 ScreenLysP - ABDLys2HB+ 
LD1094463 LD1094463 LD1094463 ScreenLysP - ABDLys2HXX 

2 个答案:

答案 0 :(得分:1)

看看这些DotNetPearls示例:

http://www.dotnetperls.com/split

答案 1 :(得分:0)

您可以使用正则表达式来拆分文本。这是一些有趣的链接:

希望这有帮助。