【发布时间】:2019-08-05 09:05:54
【问题描述】:
我有一个string 填写了这样的内容 -
".... . -.-- .--- ..- -.. ."
我需要将其拆分到子字符串,但是中间的空格也必须写入字符串数组。
public static string Decode(string morseCode)
{
string[] words = morseCode.Split(new char[] { ' ' });
...
}
我希望:
words[0] = "....";
words[1] = ".";
words[2] = "-.--";
words[3] = " "; // <- Space in the middle should be preserved
words[4] = ".---";
...
【问题讨论】:
-
您可能有固定宽度的数据并且必须在列索引上拆分而不是在空格上拆分,或者您有制表符分隔的数据并且必须在制表符上而不是空格上拆分。
-
@OwenPauling 看起来不像是真正的复制品。此处的 OP 不想保留所有分隔符。只有一个具有两种含义的:作为分隔符和作为符号