commit 438b1b5d0ff7de7e2ad82f6ca90885e55103f25b Author: Eugen Höglinger Date: Thu Nov 26 17:37:27 2020 +0100 Initialize diff --git a/.vs/Test_SearchAndFind.git/v16/.suo b/.vs/Test_SearchAndFind.git/v16/.suo new file mode 100644 index 0000000..e568cf3 Binary files /dev/null and b/.vs/Test_SearchAndFind.git/v16/.suo differ diff --git a/Test_SearchAndFind.git.sln b/Test_SearchAndFind.git.sln new file mode 100644 index 0000000..c03b30f --- /dev/null +++ b/Test_SearchAndFind.git.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30413.136 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test_SearchAndFind", "Test_SearchAndFind\Test_SearchAndFind.csproj", "{866F66E5-8525-4F23-B31E-969C083A343B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {866F66E5-8525-4F23-B31E-969C083A343B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {866F66E5-8525-4F23-B31E-969C083A343B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {866F66E5-8525-4F23-B31E-969C083A343B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {866F66E5-8525-4F23-B31E-969C083A343B}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {0099A69B-4400-4B11-95FA-D55A082C8E22} + EndGlobalSection +EndGlobal diff --git a/Test_SearchAndFind/App.config b/Test_SearchAndFind/App.config new file mode 100644 index 0000000..56efbc7 --- /dev/null +++ b/Test_SearchAndFind/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Test_SearchAndFind/Form1.Designer.cs b/Test_SearchAndFind/Form1.Designer.cs new file mode 100644 index 0000000..d200ebb --- /dev/null +++ b/Test_SearchAndFind/Form1.Designer.cs @@ -0,0 +1,233 @@ +namespace Test_SearchAndFind +{ + partial class Form1 + { + /// + /// Erforderliche Designervariable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Verwendete Ressourcen bereinigen. + /// + /// True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Vom Windows Form-Designer generierter Code + + /// + /// Erforderliche Methode für die Designerunterstützung. + /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden. + /// + private void InitializeComponent() + { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); + this.textBoxText = new System.Windows.Forms.TextBox(); + this.groupBoxSearchAndFind = new System.Windows.Forms.GroupBox(); + this.checkBoxFullword = new System.Windows.Forms.CheckBox(); + this.checkBoxCase = new System.Windows.Forms.CheckBox(); + this.buttonPrevious = new System.Windows.Forms.Button(); + this.buttonNext = new System.Windows.Forms.Button(); + this.textBoxSearchstring = new System.Windows.Forms.TextBox(); + this.labelSearchstring = new System.Windows.Forms.Label(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.buttonReplaceAll = new System.Windows.Forms.Button(); + this.buttonReplace = new System.Windows.Forms.Button(); + this.textBoxReplaceText = new System.Windows.Forms.TextBox(); + this.labelReplaceText = new System.Windows.Forms.Label(); + this.buttonSelectAll = new System.Windows.Forms.Button(); + this.groupBoxSearchAndFind.SuspendLayout(); + this.groupBox1.SuspendLayout(); + this.SuspendLayout(); + // + // textBoxText + // + this.textBoxText.Location = new System.Drawing.Point(12, 13); + this.textBoxText.Multiline = true; + this.textBoxText.Name = "textBoxText"; + this.textBoxText.Size = new System.Drawing.Size(375, 425); + this.textBoxText.TabIndex = 0; + this.textBoxText.Text = resources.GetString("textBoxText.Text"); + // + // groupBoxSearchAndFind + // + this.groupBoxSearchAndFind.Controls.Add(this.buttonSelectAll); + this.groupBoxSearchAndFind.Controls.Add(this.checkBoxFullword); + this.groupBoxSearchAndFind.Controls.Add(this.checkBoxCase); + this.groupBoxSearchAndFind.Controls.Add(this.buttonPrevious); + this.groupBoxSearchAndFind.Controls.Add(this.buttonNext); + this.groupBoxSearchAndFind.Controls.Add(this.textBoxSearchstring); + this.groupBoxSearchAndFind.Controls.Add(this.labelSearchstring); + this.groupBoxSearchAndFind.Location = new System.Drawing.Point(395, 13); + this.groupBoxSearchAndFind.Name = "groupBoxSearchAndFind"; + this.groupBoxSearchAndFind.Size = new System.Drawing.Size(393, 123); + this.groupBoxSearchAndFind.TabIndex = 1; + this.groupBoxSearchAndFind.TabStop = false; + this.groupBoxSearchAndFind.Text = "Search and Find"; + // + // checkBoxFullword + // + this.checkBoxFullword.AutoSize = true; + this.checkBoxFullword.Location = new System.Drawing.Point(6, 68); + this.checkBoxFullword.Name = "checkBoxFullword"; + this.checkBoxFullword.Size = new System.Drawing.Size(88, 17); + this.checkBoxFullword.TabIndex = 6; + this.checkBoxFullword.Text = "Ganzes Wort"; + this.checkBoxFullword.UseVisualStyleBackColor = true; + this.checkBoxFullword.CheckedChanged += new System.EventHandler(this.checkBoxFullword_CheckedChanged); + // + // checkBoxCase + // + this.checkBoxCase.AutoSize = true; + this.checkBoxCase.Location = new System.Drawing.Point(6, 45); + this.checkBoxCase.Name = "checkBoxCase"; + this.checkBoxCase.Size = new System.Drawing.Size(181, 17); + this.checkBoxCase.TabIndex = 5; + this.checkBoxCase.Text = "Groß-/Kleinschreibung ignorieren"; + this.checkBoxCase.UseVisualStyleBackColor = true; + this.checkBoxCase.CheckedChanged += new System.EventHandler(this.checkBoxCase_CheckedChanged); + // + // buttonPrevious + // + this.buttonPrevious.Location = new System.Drawing.Point(6, 91); + this.buttonPrevious.Name = "buttonPrevious"; + this.buttonPrevious.Size = new System.Drawing.Size(91, 23); + this.buttonPrevious.TabIndex = 4; + this.buttonPrevious.Text = "Voriger"; + this.buttonPrevious.UseVisualStyleBackColor = true; + this.buttonPrevious.Click += new System.EventHandler(this.buttonPrevious_Click); + // + // buttonNext + // + this.buttonNext.Location = new System.Drawing.Point(151, 91); + this.buttonNext.Name = "buttonNext"; + this.buttonNext.Size = new System.Drawing.Size(91, 23); + this.buttonNext.TabIndex = 3; + this.buttonNext.Text = "Nächster"; + this.buttonNext.UseVisualStyleBackColor = true; + this.buttonNext.Click += new System.EventHandler(this.buttonNext_Click); + // + // textBoxSearchstring + // + this.textBoxSearchstring.Location = new System.Drawing.Point(61, 19); + this.textBoxSearchstring.Name = "textBoxSearchstring"; + this.textBoxSearchstring.Size = new System.Drawing.Size(326, 20); + this.textBoxSearchstring.TabIndex = 1; + this.textBoxSearchstring.TextChanged += new System.EventHandler(this.textBoxSearchstring_TextChanged); + this.textBoxSearchstring.KeyDown += new System.Windows.Forms.KeyEventHandler(this.textBoxSearchstring_KeyDown); + // + // labelSearchstring + // + this.labelSearchstring.AutoSize = true; + this.labelSearchstring.Location = new System.Drawing.Point(6, 22); + this.labelSearchstring.Name = "labelSearchstring"; + this.labelSearchstring.Size = new System.Drawing.Size(49, 13); + this.labelSearchstring.TabIndex = 0; + this.labelSearchstring.Text = "Suchtext"; + // + // groupBox1 + // + this.groupBox1.Controls.Add(this.buttonReplaceAll); + this.groupBox1.Controls.Add(this.buttonReplace); + this.groupBox1.Controls.Add(this.textBoxReplaceText); + this.groupBox1.Controls.Add(this.labelReplaceText); + this.groupBox1.Location = new System.Drawing.Point(395, 143); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(393, 77); + this.groupBox1.TabIndex = 2; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "Replace with"; + // + // buttonReplaceAll + // + this.buttonReplaceAll.Location = new System.Drawing.Point(296, 46); + this.buttonReplaceAll.Name = "buttonReplaceAll"; + this.buttonReplaceAll.Size = new System.Drawing.Size(91, 23); + this.buttonReplaceAll.TabIndex = 3; + this.buttonReplaceAll.Text = "Alle Ersetzen"; + this.buttonReplaceAll.UseVisualStyleBackColor = true; + this.buttonReplaceAll.Click += new System.EventHandler(this.buttonReplaceAll_Click); + // + // buttonReplace + // + this.buttonReplace.Location = new System.Drawing.Point(6, 46); + this.buttonReplace.Name = "buttonReplace"; + this.buttonReplace.Size = new System.Drawing.Size(91, 23); + this.buttonReplace.TabIndex = 2; + this.buttonReplace.Text = "Ersetzen"; + this.buttonReplace.UseVisualStyleBackColor = true; + this.buttonReplace.Click += new System.EventHandler(this.buttonReplace_Click); + // + // textBoxReplaceText + // + this.textBoxReplaceText.Location = new System.Drawing.Point(65, 20); + this.textBoxReplaceText.Name = "textBoxReplaceText"; + this.textBoxReplaceText.Size = new System.Drawing.Size(322, 20); + this.textBoxReplaceText.TabIndex = 1; + this.textBoxReplaceText.KeyDown += new System.Windows.Forms.KeyEventHandler(this.textBoxReplaceText_KeyDown); + // + // labelReplaceText + // + this.labelReplaceText.AutoSize = true; + this.labelReplaceText.Location = new System.Drawing.Point(6, 23); + this.labelReplaceText.Name = "labelReplaceText"; + this.labelReplaceText.Size = new System.Drawing.Size(53, 13); + this.labelReplaceText.TabIndex = 0; + this.labelReplaceText.Text = "Ersetztext"; + // + // buttonSelectAll + // + this.buttonSelectAll.Enabled = false; + this.buttonSelectAll.Location = new System.Drawing.Point(296, 91); + this.buttonSelectAll.Name = "buttonSelectAll"; + this.buttonSelectAll.Size = new System.Drawing.Size(91, 23); + this.buttonSelectAll.TabIndex = 3; + this.buttonSelectAll.Text = "Alle Auswählen"; + this.buttonSelectAll.UseVisualStyleBackColor = true; + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.groupBox1); + this.Controls.Add(this.groupBoxSearchAndFind); + this.Controls.Add(this.textBoxText); + this.Name = "Form1"; + this.Text = "Test_Saerch, Find and Replace"; + this.Load += new System.EventHandler(this.Form1_Load); + this.groupBoxSearchAndFind.ResumeLayout(false); + this.groupBoxSearchAndFind.PerformLayout(); + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.TextBox textBoxText; + private System.Windows.Forms.GroupBox groupBoxSearchAndFind; + private System.Windows.Forms.Button buttonPrevious; + private System.Windows.Forms.Button buttonNext; + private System.Windows.Forms.TextBox textBoxSearchstring; + private System.Windows.Forms.Label labelSearchstring; + private System.Windows.Forms.CheckBox checkBoxCase; + private System.Windows.Forms.CheckBox checkBoxFullword; + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.Button buttonReplaceAll; + private System.Windows.Forms.Button buttonReplace; + private System.Windows.Forms.TextBox textBoxReplaceText; + private System.Windows.Forms.Label labelReplaceText; + private System.Windows.Forms.Button buttonSelectAll; + } +} + diff --git a/Test_SearchAndFind/Form1.cs b/Test_SearchAndFind/Form1.cs new file mode 100644 index 0000000..aa510da --- /dev/null +++ b/Test_SearchAndFind/Form1.cs @@ -0,0 +1,381 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Test_SearchAndFind +{ + public partial class Form1 : Form + { + #region Version und Copyright + // Version und Copyright + string programName = Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); //Den Programmnamen auslesen + string programVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); + static object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false); + string copyright = GenerateCopyright(); + string icon = Application.StartupPath + "\\Info.bmp"; + //Assembly Datum und Zeit + static DateTime value = AssemblyDateTime(); + string date = value.ToShortDateString(); + string time = value.ToLongTimeString(); + private static DateTime AssemblyDateTime() + { + var version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; + var buildDateTime = new DateTime(2000, 1, 1).Add(new TimeSpan(TimeSpan.TicksPerDay * version.Build + TimeSpan.TicksPerSecond * 2 * version.Revision)); + //Tage seit dem 1. Januar 2000 und Sekunden seit Mitternacht, (multiplizier mit 2 ergibt das Original) + return buildDateTime; + } + + private static string CurrentYear() + { + DateTime dtn = DateTime.Now; + return dtn.Year.ToString(); + } + + private static string StartYear() + { + string startYear = ((AssemblyCopyrightAttribute)attributes[0]).Copyright; + return startYear.Remove(0, startYear.LastIndexOf(" ") + 1); + } + + private static string GenerateCopyright() + { + string startYear = StartYear(); + string currentYear = CurrentYear(); + + if (startYear == currentYear) + { + return ((AssemblyCopyrightAttribute)attributes[0]).Copyright; + } + else + { + return String.Concat(((AssemblyCopyrightAttribute)attributes[0]).Copyright, "-", currentYear); + } + } + #endregion + + #region Programm-Info + /// + /// Contains the name of the program file + /// + public static string ProgramName { set; get; } + + /// + /// Contains the version of the program file + /// + public static string ProgramVersion { set; get; } + + /// + /// Contains the copyright notice + /// + public static string Copyright { set; get; } + + private void SetProgramInfo() + { + //Name, Version und Copyright setzen + ProgramName = programName; + ProgramVersion = programVersion; + Copyright = copyright; + } + #endregion + public Form1() + { + SetProgramInfo(); + InitializeComponent(); + } + + private void Form1_Load(object sender, EventArgs e) + { + this.Text = String.Concat("Test_Search, Find and Replace - Version: ", ProgramVersion, " - ", Copyright, " by E. Höglinger"); + textBoxText.Focus(); + textBoxText.Select(0, 0); + + //textBoxSearchstring.Focus(); + //textBoxSearchstring.Text = ""; + this.ActiveControl = textBoxSearchstring; + } + + List AllPositions = new List(); + int SelectedPosition { set; get; } + + private List Positions(string myText, string searchText) + { + List pos = new List(); + + if (String.IsNullOrEmpty(myText) || String.IsNullOrEmpty(searchText)) + { + return pos; + } + + int tempPos = 0; + int currentPos = 0; + + while (myText.Contains(searchText)) + { + if (checkBoxFullword.Checked) + { + //Nur ganzes Wort suchen + currentPos = IndexOfWord(myText, searchText); + } + else + { + //Suchstring suchen + currentPos = myText.IndexOf(searchText); + } + + tempPos += currentPos; + pos.Add(tempPos); + tempPos += searchText.Length; + + myText = myText.Remove(0, currentPos + searchText.Length); + + if (currentPos == -1) + { + break; + } + } + + return pos; + } + + private Regex myRegex; + + public int IndexOfWord(string myString, string myWord) + { + myRegex = new Regex("\\b" + Regex.Escape(myWord) + "\\b", RegexOptions.Compiled); + + Match mtch = myRegex.Match(myString); + + if (mtch.Success) + return mtch.Index; + else + return -1; + } + + private void Search() + { + AllPositions.Clear(); + + string fullText = textBoxText.Text; + string searchText = textBoxSearchstring.Text; + + if (checkBoxCase.Checked) + { + //Groß-/Kleinschreibung ignorieren + fullText = fullText.ToLower(); + searchText = searchText.ToLower(); + } + + if (!String.IsNullOrEmpty(searchText) && fullText.Contains(searchText)) + { + AllPositions = Positions(fullText, searchText); + + SelectedPosition = 0; + + if (AllPositions[SelectedPosition] != -1) + { + SelectSearchString(AllPositions[SelectedPosition], searchText.Length); + } + else + { + MessageBox.Show("Es wurde kein (weiterer) Suchtext gefunden"); + } + } + else + { + MessageBox.Show("Es wurde kein (weiterer) Suchtext gefunden"); + } + } + + private void Previous() + { + if (!String.IsNullOrEmpty(textBoxSearchstring.Text)) + { + if (AllPositions.Count == 0) + { + Search(); + if (textBoxText.Text.Contains(textBoxSearchstring.Text)) + { + Previous(); //Den letzten gefundenen Suchstring selektieren + } + } + else if (SelectedPosition > 0) + { + //Position um eins verringern und Suchstring im Text selektieren + SelectedPosition--; + SelectSearchString(AllPositions[SelectedPosition], textBoxSearchstring.Text.Length); + } + else + { + //Selected Position auf die letzte Position setzten und Suchstring im Text selektieren + SelectedPosition = AllPositions.Count - 1; + SelectSearchString(AllPositions[SelectedPosition], textBoxSearchstring.Text.Length); + } + } + } + + private void Next() + { + if (!String.IsNullOrEmpty(textBoxSearchstring.Text)) + { + if (AllPositions.Count == 0) + { + Search(); + } + else if (SelectedPosition + 1 < AllPositions.Count) + { + //Position um eins erhöhen und Suchstring im Text selektieren + SelectedPosition++; + SelectSearchString(AllPositions[SelectedPosition], textBoxSearchstring.Text.Length); + } + else + { + //Selected Position auf 0 setzten und Suchstring im Text selektieren + SelectedPosition = 0; + SelectSearchString(AllPositions[SelectedPosition], textBoxSearchstring.Text.Length); + } + } + } + + private int Replace() + { + if (AllPositions[SelectedPosition] != -1) + { + textBoxText.Text = textBoxText.Text.Remove(AllPositions[SelectedPosition], textBoxSearchstring.Text.Length); + textBoxText.Text = textBoxText.Text.Insert(AllPositions[SelectedPosition], textBoxReplaceText.Text); + textBoxText.Refresh(); + Search(); //Neu durchsuchen, damit die Starindexes wieder passen + return 0; //Ende noch nicht erreicht + } + else + { + return -1; //Ende erreicht + } + } + + private void ReplaceAll() + { + string fullText = textBoxText.Text; + string searchText = textBoxSearchstring.Text; + + if (checkBoxCase.Checked) + { + //Groß-/Kleinschreibung ignorieren + fullText = fullText.ToLower(); + searchText = searchText.ToLower(); + } + + int nextRun = 0; + + while (fullText.Contains(searchText) && nextRun != -1) + { + nextRun = Replace(); + fullText = textBoxText.Text; + + if (checkBoxCase.Checked) + { + //Groß-/Kleinschreibung ignorieren + fullText = fullText.ToLower(); + } + } + + textBoxReplaceText.Focus(); + } + + private void SelectSearchString(int position, int length) + { + if (position != -1) + { + textBoxText.Focus(); + textBoxText.Select(position, length); + textBoxText.Refresh(); + } + } + + private void textBoxSearchstring_KeyDown(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.Enter) + { + Search(); + + + //TODO: Test + var suche = new Search(textBoxText.Text, textBoxSearchstring.Text, checkBoxCase.Checked, checkBoxFullword.Checked); + string pos = "Es wurden " + suche.AllPositions.Count + " Übereinstimmungen\r\nan diesen Positionen gefunden:"; + foreach (var item in suche.AllPositions) + { + pos = String.Concat(pos, "\r\n", item); + } + pos = String.Concat(pos, "\r\nAktuelle Cursor Position: ", suche.CurrentCursorPosition, "\r\nEs ist ein Fehler passiert: ", suche.Error.ToString()); + MessageBox.Show(pos); + for (int i = 0; i < 6; i++) + { + suche.NextPosition(); + MessageBox.Show(pos + "\r\n\r\nIndex erhöhen\r\nIndex: " + suche.Index + "\r\nCursorposition: " + suche.CurrentCursorPosition); + } + for (int i = 0; i < 8; i++) + { + suche.PreviousPosition(); + MessageBox.Show(pos + "\r\n\r\nIndex veringern\r\nIndex: " + suche.Index + "\r\nCursorposition: " + suche.CurrentCursorPosition); + } + } + } + + private void textBoxSearchstring_TextChanged(object sender, EventArgs e) + { + AllPositions.Clear(); + } + + private void checkBoxCase_CheckedChanged(object sender, EventArgs e) + { + if (!String.IsNullOrEmpty(textBoxSearchstring.Text)) + { + Search(); + } + } + + private void checkBoxFullword_CheckedChanged(object sender, EventArgs e) + { + if (!String.IsNullOrEmpty(textBoxSearchstring.Text)) + { + Search(); + } + } + + private void buttonPrevious_Click(object sender, EventArgs e) + { + Previous(); + } + + private void buttonNext_Click(object sender, EventArgs e) + { + Next(); + } + + private void textBoxReplaceText_KeyDown(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.Enter) + { + textBoxText.Focus(); + } + } + + private void buttonReplace_Click(object sender, EventArgs e) + { + Replace(); + } + + private void buttonReplaceAll_Click(object sender, EventArgs e) + { + ReplaceAll(); + } + } +} diff --git a/Test_SearchAndFind/Form1.resx b/Test_SearchAndFind/Form1.resx new file mode 100644 index 0000000..c077f9d --- /dev/null +++ b/Test_SearchAndFind/Form1.resx @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Das ist ein Probetext. Er dient zum Testen einer Suchen und Finden Funktion. +Wird ein angegebener Suchstring im Text gefunden, dann wird die Textstelle selektiert. +Ist der Suchstring nicht im Text enthalten, dann wird eine Meldung ausgegeben. +Mit "Nächster" wird im Text nach dem nächsten Vorkommen des Suchstrings gesucht. Wird ein weiteres Vorkommen gefunden, dann wird die Textstelle markiert. +"Voriger" hat die gleiche Funktion wie "Nächster", nur ist die Suchrichtung rückwärts. +Die Anderen Optionen müssen noch definiert werden. + + + \ No newline at end of file diff --git a/Test_SearchAndFind/Program.cs b/Test_SearchAndFind/Program.cs new file mode 100644 index 0000000..325bbbf --- /dev/null +++ b/Test_SearchAndFind/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Test_SearchAndFind +{ + static class Program + { + /// + /// Der Haupteinstiegspunkt für die Anwendung. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/Test_SearchAndFind/Properties/AssemblyInfo.cs b/Test_SearchAndFind/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..0d084fc --- /dev/null +++ b/Test_SearchAndFind/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Allgemeine Informationen über eine Assembly werden über die folgenden +// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, +// die einer Assembly zugeordnet sind. +[assembly: AssemblyTitle("Test_SearchAndFind")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Test_SearchAndFind")] +[assembly: AssemblyCopyright("Copyright © 2020")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly +// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von +// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen. +[assembly: ComVisible(false)] + +// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird +[assembly: Guid("866f66e5-8525-4f23-b31e-969c083a343b")] + +// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: +// +// Hauptversion +// Nebenversion +// Buildnummer +// Revision +// +// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, +// indem Sie "*" wie unten gezeigt eingeben: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Test_SearchAndFind/Properties/Resources.Designer.cs b/Test_SearchAndFind/Properties/Resources.Designer.cs new file mode 100644 index 0000000..7ded21f --- /dev/null +++ b/Test_SearchAndFind/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion: 4.0.30319.42000 +// +// Änderungen an dieser Datei können fehlerhaftes Verhalten verursachen und gehen verloren, wenn +// der Code neu generiert wird. +// +//------------------------------------------------------------------------------ + +namespace Test_SearchAndFind.Properties +{ + + + /// + /// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. + /// + // Diese Klasse wurde von der StronglyTypedResourceBuilder-Klasse + // über ein Tool wie ResGen oder Visual Studio automatisch generiert. + // Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen + // mit der Option /str erneut aus, oder erstellen Sie Ihr VS-Projekt neu. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Test_SearchAndFind.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle + /// Ressourcenlookups, die diese stark typisierte Ressourcenklasse verwenden. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/Test_SearchAndFind/Properties/Resources.resx b/Test_SearchAndFind/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/Test_SearchAndFind/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Test_SearchAndFind/Properties/Settings.Designer.cs b/Test_SearchAndFind/Properties/Settings.Designer.cs new file mode 100644 index 0000000..d0f0fc4 --- /dev/null +++ b/Test_SearchAndFind/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Test_SearchAndFind.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/Test_SearchAndFind/Properties/Settings.settings b/Test_SearchAndFind/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/Test_SearchAndFind/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Test_SearchAndFind/Search.cs b/Test_SearchAndFind/Search.cs new file mode 100644 index 0000000..b2d9e68 --- /dev/null +++ b/Test_SearchAndFind/Search.cs @@ -0,0 +1,139 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; + +namespace Test_SearchAndFind +{ + class Search + { + /// + /// Searches the specified string in a text + /// + /// Text to be searched. + /// Character string to be searched. + /// Should be ignored upper/lower case. + /// Should only be searched for a whole word. + public Search(string text, string searchString, bool noCaseSensitve, bool onlyFullWord) + { + Text = text; + SearchString = searchString; + NoCaseSensitve = noCaseSensitve; + OnlyFullWord = onlyFullWord; + + SearchEntities(); + CurrentCursorPosition = AllPositions[0]; + Index = 0; + } + + private string Text { set; get; } + private string SearchString { set; get; } + private bool NoCaseSensitve { set; get; } + private bool OnlyFullWord { set; get; } + public int Index { private set; get; } + public int CurrentCursorPosition { set; get; } + public List AllPositions { set; get; } + public bool Error { set; get; } + + private void SearchEntities() + { + Error = false; + + string text = Text; + string searchString = SearchString; + + if (NoCaseSensitve) + { + //Groß-/Kleinschreibung ignorieren + text = text.ToLower(); + searchString = searchString.ToLower(); + } + + if (!String.IsNullOrEmpty(searchString) && text.Contains(searchString)) + { + AllPositions = Positions(text, searchString); + } + else + { + Error = true; + } + } + + private List Positions(string text, string searchString) + { + List positions = new List(); + + if (String.IsNullOrEmpty(text) || String.IsNullOrEmpty(searchString)) + { + return positions; + } + + int position = 0; + int currentPos = 0; + + while (text.Contains(searchString)) + { + if (OnlyFullWord) + { + //Nur ganzes Wort suchen + currentPos = IndexOfWord(text, searchString); + } + else + { + //Suchstring suchen + currentPos = text.IndexOf(searchString); + } + + position += currentPos; + positions.Add(position); + position += searchString.Length; + + text = text.Remove(0, currentPos + searchString.Length); + } + + return positions; + } + + private Regex myRegex; + + private int IndexOfWord(string myString, string myWord) + { + myRegex = new Regex("\\b" + Regex.Escape(myWord) + "\\b", RegexOptions.Compiled); + + Match mtch = myRegex.Match(myString); + + if (mtch.Success) + return mtch.Index; + else + return -1; + } + + public void NextPosition() + { + if (Index + 1 < AllPositions.Count) + { + Index++; + } + else + { + Index = 0; + } + CurrentCursorPosition = AllPositions[Index]; + } + + public void PreviousPosition() + { + if (Index > 0) + { + Index--; + } + else + { + Index = AllPositions.Count - 1; + } + CurrentCursorPosition = AllPositions[Index]; + } + } +} diff --git a/Test_SearchAndFind/Test_SearchAndFind.csproj b/Test_SearchAndFind/Test_SearchAndFind.csproj new file mode 100644 index 0000000..9129127 --- /dev/null +++ b/Test_SearchAndFind/Test_SearchAndFind.csproj @@ -0,0 +1,84 @@ + + + + + Debug + AnyCPU + {866F66E5-8525-4F23-B31E-969C083A343B} + WinExe + Test_SearchAndFind + Test_SearchAndFind + v4.7.2 + 512 + true + false + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + Form + + + Form1.cs + + + + + + Form1.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + \ No newline at end of file diff --git a/Test_SearchAndFind/bin/Debug/Test_SearchAndFind.exe b/Test_SearchAndFind/bin/Debug/Test_SearchAndFind.exe new file mode 100644 index 0000000..3fd6906 Binary files /dev/null and b/Test_SearchAndFind/bin/Debug/Test_SearchAndFind.exe differ diff --git a/Test_SearchAndFind/bin/Debug/Test_SearchAndFind.exe.config b/Test_SearchAndFind/bin/Debug/Test_SearchAndFind.exe.config new file mode 100644 index 0000000..56efbc7 --- /dev/null +++ b/Test_SearchAndFind/bin/Debug/Test_SearchAndFind.exe.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Test_SearchAndFind/bin/Debug/Test_SearchAndFind.pdb b/Test_SearchAndFind/bin/Debug/Test_SearchAndFind.pdb new file mode 100644 index 0000000..7975367 Binary files /dev/null and b/Test_SearchAndFind/bin/Debug/Test_SearchAndFind.pdb differ diff --git a/Test_SearchAndFind/obj/Debug/.NETFramework,Version=v4.7.2.AssemblyAttributes.cs b/Test_SearchAndFind/obj/Debug/.NETFramework,Version=v4.7.2.AssemblyAttributes.cs new file mode 100644 index 0000000..3871b18 --- /dev/null +++ b/Test_SearchAndFind/obj/Debug/.NETFramework,Version=v4.7.2.AssemblyAttributes.cs @@ -0,0 +1,4 @@ +// +using System; +using System.Reflection; +[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] diff --git a/Test_SearchAndFind/obj/Debug/DesignTimeResolveAssemblyReferences.cache b/Test_SearchAndFind/obj/Debug/DesignTimeResolveAssemblyReferences.cache new file mode 100644 index 0000000..d277094 Binary files /dev/null and b/Test_SearchAndFind/obj/Debug/DesignTimeResolveAssemblyReferences.cache differ diff --git a/Test_SearchAndFind/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/Test_SearchAndFind/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache new file mode 100644 index 0000000..790e771 Binary files /dev/null and b/Test_SearchAndFind/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ diff --git a/Test_SearchAndFind/obj/Debug/Test_SearchAndFind.Form1.resources b/Test_SearchAndFind/obj/Debug/Test_SearchAndFind.Form1.resources new file mode 100644 index 0000000..060e171 Binary files /dev/null and b/Test_SearchAndFind/obj/Debug/Test_SearchAndFind.Form1.resources differ diff --git a/Test_SearchAndFind/obj/Debug/Test_SearchAndFind.Properties.Resources.resources b/Test_SearchAndFind/obj/Debug/Test_SearchAndFind.Properties.Resources.resources new file mode 100644 index 0000000..6c05a97 Binary files /dev/null and b/Test_SearchAndFind/obj/Debug/Test_SearchAndFind.Properties.Resources.resources differ diff --git a/Test_SearchAndFind/obj/Debug/Test_SearchAndFind.csproj.CoreCompileInputs.cache b/Test_SearchAndFind/obj/Debug/Test_SearchAndFind.csproj.CoreCompileInputs.cache new file mode 100644 index 0000000..c2b5e67 --- /dev/null +++ b/Test_SearchAndFind/obj/Debug/Test_SearchAndFind.csproj.CoreCompileInputs.cache @@ -0,0 +1 @@ +2a96740960e50e6c55cf6f0130a6b2560ebb598b diff --git a/Test_SearchAndFind/obj/Debug/Test_SearchAndFind.csproj.FileListAbsolute.txt b/Test_SearchAndFind/obj/Debug/Test_SearchAndFind.csproj.FileListAbsolute.txt new file mode 100644 index 0000000..06042d2 --- /dev/null +++ b/Test_SearchAndFind/obj/Debug/Test_SearchAndFind.csproj.FileListAbsolute.txt @@ -0,0 +1,10 @@ +H:\Programmieren\Git-Repository\VisualStudio\2017\_TEST\Test_SearchAndFind.git\Test_SearchAndFind\bin\Debug\Test_SearchAndFind.exe.config +H:\Programmieren\Git-Repository\VisualStudio\2017\_TEST\Test_SearchAndFind.git\Test_SearchAndFind\bin\Debug\Test_SearchAndFind.exe +H:\Programmieren\Git-Repository\VisualStudio\2017\_TEST\Test_SearchAndFind.git\Test_SearchAndFind\bin\Debug\Test_SearchAndFind.pdb +H:\Programmieren\Git-Repository\VisualStudio\2017\_TEST\Test_SearchAndFind.git\Test_SearchAndFind\obj\Debug\Test_SearchAndFind.csprojAssemblyReference.cache +H:\Programmieren\Git-Repository\VisualStudio\2017\_TEST\Test_SearchAndFind.git\Test_SearchAndFind\obj\Debug\Test_SearchAndFind.Form1.resources +H:\Programmieren\Git-Repository\VisualStudio\2017\_TEST\Test_SearchAndFind.git\Test_SearchAndFind\obj\Debug\Test_SearchAndFind.Properties.Resources.resources +H:\Programmieren\Git-Repository\VisualStudio\2017\_TEST\Test_SearchAndFind.git\Test_SearchAndFind\obj\Debug\Test_SearchAndFind.csproj.GenerateResource.cache +H:\Programmieren\Git-Repository\VisualStudio\2017\_TEST\Test_SearchAndFind.git\Test_SearchAndFind\obj\Debug\Test_SearchAndFind.csproj.CoreCompileInputs.cache +H:\Programmieren\Git-Repository\VisualStudio\2017\_TEST\Test_SearchAndFind.git\Test_SearchAndFind\obj\Debug\Test_SearchAndFind.exe +H:\Programmieren\Git-Repository\VisualStudio\2017\_TEST\Test_SearchAndFind.git\Test_SearchAndFind\obj\Debug\Test_SearchAndFind.pdb diff --git a/Test_SearchAndFind/obj/Debug/Test_SearchAndFind.csproj.GenerateResource.cache b/Test_SearchAndFind/obj/Debug/Test_SearchAndFind.csproj.GenerateResource.cache new file mode 100644 index 0000000..4f79dba Binary files /dev/null and b/Test_SearchAndFind/obj/Debug/Test_SearchAndFind.csproj.GenerateResource.cache differ diff --git a/Test_SearchAndFind/obj/Debug/Test_SearchAndFind.csprojAssemblyReference.cache b/Test_SearchAndFind/obj/Debug/Test_SearchAndFind.csprojAssemblyReference.cache new file mode 100644 index 0000000..f1e9cf7 Binary files /dev/null and b/Test_SearchAndFind/obj/Debug/Test_SearchAndFind.csprojAssemblyReference.cache differ diff --git a/Test_SearchAndFind/obj/Debug/Test_SearchAndFind.exe b/Test_SearchAndFind/obj/Debug/Test_SearchAndFind.exe new file mode 100644 index 0000000..3fd6906 Binary files /dev/null and b/Test_SearchAndFind/obj/Debug/Test_SearchAndFind.exe differ diff --git a/Test_SearchAndFind/obj/Debug/Test_SearchAndFind.pdb b/Test_SearchAndFind/obj/Debug/Test_SearchAndFind.pdb new file mode 100644 index 0000000..7975367 Binary files /dev/null and b/Test_SearchAndFind/obj/Debug/Test_SearchAndFind.pdb differ