2012-01-17 1 views
1

마지막 질문이 명확하지 않으므로 여기 두 번째 시도가 있습니다.콘솔에서 특수 문자를 제거하여 txt 파일로드

"C:\Dokumente und Einstellungen\Bektas\Desktop\test\text1.txt" 

어떻게 자동으로 " 문자를 제거 할 수 있습니다 : 나는 드래그하여 콘솔에 내 txt 파일을 삭제하면

, 나는 이런 경로를 얻을? 당신은 자동으로 이런 일을 수행하여 " 문자를 제거 할 수

static void Main(string[] args) 
    { 
     String pfad; 
     String pfad2; 
     String speichern = "C:\\Dokumente und Einstellungen\\Bektas\\Desktop\\test\\ausgabe.txt"; 

     try 
     { 
      Console.WriteLine("Pfad eingeben: "); 
      pfad = Console.ReadLine(); 

      Console.WriteLine("Pfad eingeben: "); 
      pfad2 = Console.ReadLine(); 
      // Input 
      List<String> data = File.ReadAllLines(pfad) 
       .Concat(File.ReadAllLines(pfad2)) 
       .Distinct().ToList(); 

      // Processing 
      data.Sort(); 

      // Output 
      Console.WriteLine("Duplikate entfernt & sortiert:"); 
      data.ForEach(Console.WriteLine); 
      File.WriteAllLines(speichern, data.ToArray()); 

     } 
     catch (Exception e) 
     { 
      Console.WriteLine("Die Anwendung schlug fehl: {0}\t" + e.ToString()); 
     } 

     Console.ReadKey(); 

    } 
} 
+1

당신은 당신의 질문을 지정하세요 수 있을까? 그 숯불을 어디에서 파 내야합니까? –

답변

3

: 내가 문자열로 내 경로를 저장하기 전에 손으로이를 삭제해야

는 ... 여기

내 코드입니다

또한
Console.WriteLine("Pfad eingeben: "); 
pfad = Console.ReadLine(); 
if (pfad.StartsWith("\"") && pfad.EndsWith("\"")) { 
    pfad = pfad.Substring(1, pfad.Length - 2); 
} 

, 당신은 pfadpfad2로 두 번이 일을하고 있기 때문에, 당신은이 코드를 추출한다 코드 중복을 줄이기 위해 기능 :

private static string RemoveQuotes(string input) { 
    if (input.StartsWith("\"") && input.EndsWith("\"")) { 
     return input.Substring(1, input.Length - 2); 
    } else { 
     return input; 
    } 
} 

public static void Main(string[] args) { 

    // ... 

    Console.WriteLine("Pfad eingeben: "); 
    pfad = RemoveQuotes(Console.ReadLine()); 

    Console.WriteLine("Pfad eingeben: "); 
    pfad2 = RemoveQuotes(Console.ReadLine());  

    // ... 

}

1

pfad = pfad.Replace("\"", "");는 아무것도 "모두 대체합니다.

0

당신의 "특별한 문자열이"하나 개의 문자가 다음과 같이 이상 해당하는 경우 :

string replacedString = Regex.Replace(originalString, specialString); 
관련 문제