【发布时间】:2018-02-15 02:20:11
【问题描述】:
我有一个字符串如下:
查理辛很酷
BBBB
他喜欢跑步
BBB
他什么时候跑?
BBBB他住在这里
BBBB
?
[
我喜欢查理辛
BBBB
我想将字符串分成两个不同的数组。一个用于 B 顶部的短语和 B 本身。或者更好的是,有一本字典,其中短语作为键,B 作为值。我还想忽略所有空行和不以字母开头的行。我该怎么做呢?
string[] newText = file.Split(new string[] { "\n", "\r\n",},StringSplitOptions.RemoveEmptyEntries);
int count = 0;
Regex symbol = new Regex("^[[]]$"); //these are the symbols I want to detect
Dictionary<string, string> patternedText = new Dictionary<string,string>();
foreach(string s in newText){
int bCount = 0;
count++;
bCount++; //position of where it detects a match
if(symbol.isMatch(s)){
newText[count-bCount] = s;
}else{ newText[count] = s;
patternedText.Add(newText[count],newText[count+1]);
}
基本上我希望数组的格式为:
带符号的短语
BBB
带符号的短语
BBBB
短语
带符号的 BBB
并过滤掉所有空行和任何一行上的符号,只添加到短语中。
【问题讨论】:
-
请提供一些代码!到目前为止你尝试过什么?
-
我编辑了帖子并解释了更多!对此感到抱歉
标签: c# c arrays dictionary