将包含text和serverpath的字符串拆分为数组

时间:2014-02-19 07:22:02

标签: c# regex arrays string-split

我的问题是,我有一个字符串,我想把它拆分成一个数组。例如:

我得到的字符串是

Unexpected Error: Check Availability of Data Source Failed:
\\server01\z.storage\Folder\Folder\Folder\Folder\_Folder\Folder_3\Folder\Folder\File_Fi_3.expression
 missing.
 \\server01\z.storage\Folder\Folder\Folder\Folder\_Folder\Folder_F6\Folder\Folder\File1_Fi_F2.expression
 missing. \\server01\z.storage\Folder\Folder\Fo\Folder With
 Spaces\_Folder\Folder_F6\Folder\Folder\File123.expression missing.
 Details can be found on the Server at :
 \\server01\p.programming\Software
 Unit\01_Projects\Folder\Folder-FO-Fol\Folder\Folder_ErrorLog\Folder\Folder
 With Spaces\Log\

现在我将得到一个如下所示的数组:

ArrayName[0] = "Unexpected Error: Check Availability of Data Source Failed: "
ArrayName[1] = "\\server01\z.storage\Folder\Folder\Folder\Folder\_Folder\Folder_3\Folder\Folder\File_Fi_3.expression"
ArrayName[2] = " missing."
ArrayName[3] = "\\server01\z.storage\Folder\Folder\Folder\Folder\_Folder\Folder_F6\Folder\Folder\File1_Fi_F2.expression"
ArrayName[4] = " missing."
ArrayName[5] = "\\server01\z.storage\Folder\Folder\Fo\Folder With Spaces\_Folder\Folder_F6\Folder\Folder\File123.expression"
ArrayName[6] = " missing."
ArrayName[7] = "Details can be found on the Server at : "
ArrayName[8] = "\\server01\p.programming\Software Unit\01_Projects\Folder\Folder-FO-Fol\Folder\Folder_ErrorLog\Folder\Folder With Spaces\Log\"

我已经尝试用string.Split进行拆分,但我得到的字符串文件夹路径包含空格,并且传入的字符串不是每次都有4个服务器路径...它可以更多或更少。也许有人可以帮助我:o)

1 个答案:

答案 0 :(得分:0)

如果没有新行尝试按此正则表达式进行拆分\\\\\w{1,}.*.expression\s missing