显示没有子串的字符串

Showing a string without a substring

我有点"problem"。我有这两个字符串(一个显示消息,另一个显示“##Documents##”开始的索引):

        string text = currentNode.Properties["menuEntry"].Value;
        string index = text.IndexOf("##Documents##").ToString();

我想为没有“##Documents##”的消息添加另一个字符串。从上面的代码继续的任何解决方案,或任何其他解决方案?

例如:消息:blablabla ##Documents## 123

还有我想展示的:blablabla 123

感谢并抱歉提出这个菜鸟问题。

如果找到,只需连接出现在该子字符串前后的子字符串。

int index = text.IndexOf("##Documents##");
string newText = text;
if(index > -1)
    newText = text.SubString(0, index) + text.SubString(index +13);

只需像这样使用Replace()方法:

string text = currentNode.Properties["menuEntry"].Value;
string message= text.Replace("##Documents##",string.Empty);