/// <summary> /// Method return file after simple Search and Replace, caseSentsitive optional /// </summary> /// <param name="fileContent"></param> /// <param name="searchText"></param> /// <param name="replaceText"></param> /// <param name="caseSensitive"></param> /// <returns></returns> private string ReplaceAboslute(string fileContent, string searchText, string replaceText, ResultInfo resultInfo) { //string workingString = fileContent; //try //{ // if (!this.CaseSensitive) // workingString = workingString.Replace(searchText, replaceText); // else // workingString = Regex.Replace(fileContent, searchText, replaceText, GetRegExpOption()); //} //catch (Exception ex) //{ // resultInfo.AddError("Error during replacing :" + ex.Message); //} //List<int> FoundIndexes = new List<int>(); int currentIndex = 0; StringComparison stringComparison = StringComparison.Ordinal; if (!CaseSensitive) { stringComparison = StringComparison.OrdinalIgnoreCase; } string workingString = fileContent; int foundIndex = currentIndex; while ((currentIndex < fileContent.Length) && (foundIndex > -1)) { // znajdz indeks search text, zrob substring - index + foundIndex = workingString.IndexOf(searchText, currentIndex, stringComparison); workingString = workingString.Remove(foundIndex, searchText.Length); workingString = workingString.Insert(foundIndex, replaceText); //FoundIndexes.Add(foundIndex); currentIndex = foundIndex + replaceText.Length; resultInfo.AddChange(String.Format("Replaced {} to {} in {} file position ", searchText, replaceText, foundIndex)); } return(workingString); }