2014-07-23 3 views
0

저는 C#의 초보자입니다.C# 검색 - PHP 파일로 대체

private string ReplaceBackgroundDirection(string Source) 
{ 
    return Source.Replace("\"", "'").Replace("=>","=>__(") + ",'$world'),"; 
} 
: 이것은 내 시도이다

$of_options[] = array( 'name'  =>__('General Settings','$world'), 
         ,"std" => "General Settings", 
         ,"test" => "test", 
       );  

:이 출력을 원하는

$of_options[] = array( "name"  => "General Settings", 
         ,"std" => "General Settings", 
         ,"test" => "test", 
       );   

: 나는이 입력이 &는 PHP 파일 로 대체 검색을위한 작은 도구를 만들기 위해 노력하고있어

+1

찾기 및 바꾸기 도구를 메모장이나 IDE에서 사용하지 않는 이유는 무엇입니까? – Dai

+0

무엇을하려고합니까? – flindeberg

+0

@dai 어떻게 메모장을 사용할 수 있습니까? – user3867748

답변

0

일반 표현식에서 lookbehinds와 lookaheads를 사용하면 다음 세 부분으로 대체 할 수 있습니다.

 string orig = "\"$of_options[] = array( \"name\"  => \"General Settings\", ,\"std\" => \"General Settings\", ,\"test\" => \"test\",); \""; 

     string output = Regex.Replace(orig, 
             @"(?<=array\([\s]*)""name""", 
             "'name'"); 
     output = Regex.Replace(output, 
            @"(?<='name'[\s]*\=>)[\s]*""", 
            "__('"); 
     output = Regex.Replace(output, 
            @"(?<='name'[\s]*\=>__\(['\w\s]+)\""+(?=\,)", 
            "','$world')"); 
+0

코드가 도와줍니다. 바클 릿에 감사드립니다. Source = Source.Replace ("\"name \ "=" "\"name \ '=> __ (', '$ world \') "); 하지만 출력이 __ (','$ 세계 $ 세계 '') "일반 설정", 지금은 "일반 설정"을 만드는 방법 ') – user3867748

+0

당신은''name "=>'을''name '=> __ (', '$ world')'로 대체하기 만하면됩니다. 어떤 변화가 일어나기 전에 원래의 문자열을 보여 주시고, 당신이 원하는 것을 보여 주시면 어떻게해야하는지 알려 드리겠습니다. – barrick