How to Split a String into an Array Of Strings?

人盡茶涼 提交于 2019-12-01 12:10:02

问题


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 

回答1:


Just have a look at these DotNetPearls examples:

http://www.dotnetperls.com/split




回答2:


You can use regular expressions to split your text. Here is some interesting links :

  • You can start with this : http://msdn.microsoft.com/en-us/library/aa719739%28VS.110%29.aspx
  • Quick reference langage : http://msdn.microsoft.com/en-us/library/az24scfc%28v=vs.110%29.aspx
  • A cool tool to test online your RegEx : http://regexhero.net/tester/

Hope this helps.



来源:https://stackoverflow.com/questions/19131758/how-to-split-a-string-into-an-array-of-strings

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!