如何将一个字符串分解成一个字符串数组? [英] How to Split a String into an Array Of Strings?
本文介绍了如何将一个字符串分解成一个字符串数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
其实我阅读的xps.file在我的计划。我的XPS文件应该是这样的
我下面的代码粘贴
列表<串GT; LDATA =新的List<串GT;();使用
(XpsDocument xpsDoc =新XpsDocument(文件名,System.IO.FileAccess.Read))
{
文档序列docSeq = xpsDoc.GetFixedDocumentSequence();
&字典LT;字符串,字符串> docPageText =新词典<字符串,字符串>();
为(INT页次= 0;&页次LT; docSeq.DocumentPaginator.PageCount;页次++)
{
DocumentPage docPage = docSeq.DocumentPaginator.GetPage(页次);
的foreach(UIE System.Windows.UIElement在((固定页面)docPage.Visual)。孩子)
{
如果(UIE是System.Windows.Documents.Glyphs)
{
lData.Add(((System.Windows.Documents.Glyphs)UIE).UnicodeString);
}
}
}
}
通过使用上面的代码我得到的元素列表。在此基础上我得到与空格
的foreach(在Idata串elmnt)$分隔字符串b $ b {
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
解决方案
随便看看这些DotNetPearls例子:
HTTP: //www.dotnetperls.com/split
Actually i am reading an xps.file in to my Program. My xps file should be like this
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:
http://www.dotnetperls.com/split
这篇关于如何将一个字符串分解成一个字符串数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文