[英]How to Split a String into an Array Of Strings?
Actually i am reading an xps.file in to my Program. 实际上,我正在将xps.file读取到我的程序中。 My xps file should be like this
我的xps文件应该是这样的
I paste the following code 我粘贴以下代码
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);
}
}
}
}
By using the above code i am getting the List of elements. 通过使用上面的代码,我得到了元素列表。 Based on that i am getting a String separated with Space
基于此,我得到一个用空格分隔的字符串
foreach (string elmnt in lData)
{
strText += elmnt + " ";
}
From this string i want to split it. 我想从这个字符串中拆分它。 String should be like this
字符串应该像这样
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+
i want result Array should be Like this 我想要结果数组应该像这样
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
Just have a look at these DotNetPearls examples: 看看这些DotNetPearls示例:
http://www.dotnetperls.com/split http://www.dotnetperls.com/split
You can use regular expressions to split your text. 您可以使用正则表达式拆分文本。 Here is some interesting links :
这是一些有趣的链接:
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.