其實我正在閱讀一個xps.file到我的程序中。我的XPS文件應該是這樣的 如何將字符串拆分爲字符串數組?
我下面的代碼粘貼
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
所以你想要的結果是一個5×15陣列? – Dutts
第二行只有四個元素 – Corak
而不是'strText + = elmnt +「」;'你可以使用'string.Join(separator,list);' –