Compare a text file with a text template in C #?

I compared a text file with a pattern like ".." It writes the entire line to a log like this ...

 insert into depdb..fin_quick_code_met 

But I need to write this alone depdb or depdb..fin_quick_code_met

ie) I need only a word

 if (line.contains("..")) dest.WriteLine("LineNo : " + counter.ToString() + " : " +" "+ line.TrimStart()); 

How to write this word alone? Any suggestion?

+4
source share
2 answers

Sort of:

  string line = "insert into depdb..fin_quick_code_met"; foreach(Match match in Regex.Matches(line, @"(\w*)\.\.")) { Console.WriteLine(match.Groups[1]); } 

or just one (first) match in a string:

  Match match = Regex.Match(line, @"(\w*)\.\."); if (match.Success) { Console.WriteLine(match.Groups[1]); } 

Get the full depdb..fin_quick_code_met ; same code but with @"\w*\.\.\w* looking at match.Value .

+2
source

If your line contains only one entry .. then this will work

  var line= "insert into depdb..fin_quick_code_met"; if (line.contains("..")) { var splitted = line.Split(new[] { ".." }, StringSplitOptions.RemoveEmptyEntries); var firstPart = splitted.First().Split(' ').Last(); var secondPart = splitted.Last(); var composed = firstPart + ".." + secondPart; } 
+1
source

Source: https://habr.com/ru/post/1332310/


All Articles