我有一个包含加号(+)的字符串的问题.我想拆分该字符串(或者如果有其他方法来解决我的问题)
string ColumnPlusLevel = "+-J10+-J10+-J10+-J10+-J10";
string strpluslevel = "";
strpluslevel = ColumnPlusLevel;
string[] strpluslevel_lines = Regex.Split(strpluslevel, "+");
foreach (string line in strpluslevel_lines)
{
MessageBox.Show(line);
strpluslevel_summa = strpluslevel_summa + line;
}
MessageBox.Show(strpluslevel_summa, "summa sumarum");
Run Code Online (Sandbox Code Playgroud)
MessageBox用于我的测试目的.
现在...... ColumnPlusLevel字符串可以有非常多样的条目,但它始终是以加号开头的重复模式.即"+ MJ + MJ + MJ"或"+ PPL14.1 + PPL14.1 + PPL14.1"作为示例.(它来自另一个软件,我无法编辑该软件的输出)
如何找出重复的模式?在这个例子中,这是+ -J10或+ MJ或+ PPL14.1
在上面我的例子中,我通过仅使用MessageBox来测试它来显示结果,但我希望稍后将重复的模式存储在字符串中.
也许我使用Split做错了,也许有另一个解决方案.也许我以错误的方式使用Split.
希望你理解我的问题和我想要的结果.
谢谢你的建议.
/托马斯
我试图搜索一个文件,看看是否有任何行包含单词Description1并且如果在该特定行的某处有两个引号直接出现在彼此之后。
我找到了各种删除或替换它们的方法,但我想保留它们。
foreach (var line in File.ReadLines(FileName))
{
if (line.Contains ("Description1") )
{
MessageBox.Show ("Description1 found");
if (line.Contains (@"""") )
{
MessageBox.Show ("ERROR! Empty Description1 found.");
}
}
}
Run Code Online (Sandbox Code Playgroud)
搜索的文件与此类似
propertyDescriptor="22004" PropertyName="Description1" PropertyType="Part" PropertyValue="Cat" propertyDescriptor="22004" PropertyName="Description1" PropertyType="Part" PropertyValue="" propertyDescriptor="22006" PropertyName="Description2" PropertyType="Part" PropertyValue=""
错误检查应该只检测第二行中的错误,其中描述 1 和两个引号都存在。
我的问题是我在文本 Description1 的每个实例上都收到错误消息。
有什么好主意吗?
提前致谢。