2014-09-20 26 views
-1

我在文本框中有一个文本。例如:Also, edit your previous questions to improve formatting and clarity.我的字符串消失

我可以把所有的文本放在一个字符串中;我使用这个:

sline = textBox1.Text; 
string[] s = sline.Split(' '); 

但是,有时我需要一些单词在一起。例如:

Also, edit your ** previous questions to improve *** formatting and clarity. 

我需要*****之间的话。

我用这个方法:

string startWord = "**"; 
string endWord = "***"; 
int startIndex = sline.IndexOf(startWord) + startWord.Length; 
sline = sline.Substring(startIndex); 
int cutLength = sline.IndexOf(endWord); 
string result = sline.Substring(0, cutLength + 1); 

和后记,我想用不同的两个字符串。

此功能到目前为止。

我的问题:

最后,我想回馈给文本框中result串,带回完整的字[以前的问题,以改善],以后我回来了。换句话说,加questions to improve

然后,我的文本框应该是这样的:previous questions to improve questions to improve

我试图把一个在程序检查

if (s[i].ToString().Contains(result.ToString())) 
{ 
      continue; 
} 

但在这种情况下,结果很好,但所有其他人从s[i]消失。

我的目标:退回全部正文。

+0

你有什么确切的输出之间的文本??? – 2014-09-20 12:55:07

+0

相同的文本框。 – user3715465 2014-09-20 13:10:50

+0

你必须提供更多细节(代码)。这是没有道理的。 – 2014-09-20 13:23:40

回答

0

如果我正确了你的问题,你需要复制** & ****

 string strVal = "Hello **World*** one more time world" ;//your original text 
     string result = "World"; // the result u want to replace/duplicate which you got from your above operations 

     string strFinalResult = strVal.Replace("**" + result + "***", result +" " + result);//your final result 
     //Your final Result : Hello World World one more time world