2012-07-14 79 views
-4

我是編碼程序,並堆疊。請給我一個代碼,使用C#可視化Windows窗體而不是控制檯應用程序,從一個特定符號到另一個特定符號搜索文件中的文本。像文本文件中的文本c:\ id.txt在文本文件中從一個符號搜索到另一個符號

該條目已成功複製到{ea4c4653-cc65-11e1-a2fc-001e101f4e71}。

從{到}搜索字符串,並使用{和}結果,不帶。最後。並在一個消息框中發送找到的文本。代碼在文件中搜索文本並在消息框中發送整行。但我需要一部分線路。

+0

什麼'正expressions'? – Jack 2012-07-14 14:05:49

+4

你有什麼嘗試?這不是一個代碼請求網站,但我們會幫你自己弄清代碼。 – FishBasketGordo 2012-07-14 14:06:09

回答

0

Regex可能是有用的:

MessageBox.Show(
      Regex.Match(inputString, "\{(?<path>[^}]*)\}").Groups["path"].Value); 

解釋:

{  '{' 

[^}]* any character except: '}' 
     (0 or more times, matching the most amount possible) 

}  '}' 
0

嘗試使用regular expressions

var line = " The entry was successfully copied to {ea4c4653-cc65-11e1-a2fc-001e101f4e71}."; 
var foo = Regex.Match(line, @"to\s*\{([^}]+)\}"); 
if(foo.Success) { 
    MessageBox.Show(foo.Groups[1].Value); //ea4c4653-cc65-11e1-a2fc-001e101f4e71 
} else { 
    //not found value 
} 
相關問題