Skip to content

Commit

Permalink
shortened ReplaceStringAtIndex for refactorRename example
Browse files Browse the repository at this point in the history
  • Loading branch information
BZngr committed Feb 27, 2017
1 parent 439aaac commit b0d3911
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions RetailCoder.VBE/Common/CodeModuleExtensions.cs
Expand Up @@ -31,16 +31,8 @@ public static void InsertLines(this ICodeModule module, int startLine, string[]
}
private static string ReplaceStringAtIndex(string original, string toReplace, string replacement, int startIndex)
{
var stopIndex = startIndex + toReplace.Length - 1;
var prefix = original.Substring(0, startIndex);
var suffix = (stopIndex >= original.Length) ? string.Empty : original.Substring(stopIndex + 1);

if(original.Substring(startIndex, stopIndex - startIndex + 1).IndexOf(toReplace) != 0)
{
return original;
}

return prefix + toReplace.Replace(toReplace, replacement) + suffix;
var modifiedContent = original.Remove(startIndex, toReplace.Length);
return modifiedContent.Insert(startIndex, replacement);
}
}
}

0 comments on commit b0d3911

Please sign in to comment.