我想创建一个从文件中读取每一行的方法。接下来,它必须检查管道之间并确定是否存在长度超过三个字符的单词,并且只是数字。在文件中是这样组织的字符串:
发生了什么事{noway|那很酷|1293328|为什么|不知道|看}
有了这句话,软件应该去掉1293328。
结果句子将是:
发生了什么事{noway|那很酷|不知道}
到目前为止,我正在读取文件中的每一行,并制作了确定 | 之间的单词的函数。| 必须删除或不删除(检查一个像 noway 这样的字符串,这很酷等)
我不知道如何让管道之间的字符串。
您可以使用 Split 方法按字符拆分字符串。
string YourStringVariable = "{noway|that's cool|1293328|why|don't know|see}";
YourStringVariable.Split('|'); //Returns an array of the strings between the brackets
这是关于什么的:
string RemoveValues(string sentence, string[] values){
foreach(string s in values){
while(sentence.IndexOf("|" + s) != -1 && sentence.IndexOf("|" + s) != 0){
sentence = sentence.Remove(sentence.IndexOf("|" + s), s.Lenght + 1);
}
}
return sentence;
}
在你的情况下:
string[] values = new string[3]{ "1293328", "why", "see" };
string sentence = RemoveValues("noway|that's cool|1293328|why|don't know|see", values);
//result: noway|that's cool|don't know
string YourStringVariable = "{noway|that's cool|1293328|why|don't know|see}";
string[] SplitValue=g.Split('|');
string FinalValue = string.Empty;
for (int i = 0; i < SplitValue.Length; i++)
{
if (!SplitValue[i].ToString().Any(char.IsDigit))
{
FinalValue += SplitValue[i]+"|";
}
}