C#在引号之间拆分字符串

时间:2020-08-10 18:36:17

标签: c# string parsing split

在Resource.resx文件中,我有一个字段,在其中放置了一系列字符串,例如:

"string1" "string two" "this is the string 3"

我的目标是获取字符串序列。

我到目前为止所做的是:

private static string[] mystrings = Resource.str.Split(null);

但是这只是根据空格字符分割字符串。 对于第二个和第三个字符串,这是一个问题,因此最好在“”之间解析字符串。

有没有办法做到这一点?

1 个答案:

答案 0 :(得分:5)

您可以使用string.Trim删除开头/结尾的引号,然后使用string.Split并将" "作为参数来分割字符串。

private static string[] mystrings = Resource.str.Trim('"').Split("\" \"", StringSplitOptions.None);

Example Fiddle