Skip to content

Commit b0d3911

Browse files
committed
shortened ReplaceStringAtIndex for refactorRename example
1 parent 439aaac commit b0d3911

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

RetailCoder.VBE/Common/CodeModuleExtensions.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,8 @@ public static void InsertLines(this ICodeModule module, int startLine, string[]
3131
}
3232
private static string ReplaceStringAtIndex(string original, string toReplace, string replacement, int startIndex)
3333
{
34-
var stopIndex = startIndex + toReplace.Length - 1;
35-
var prefix = original.Substring(0, startIndex);
36-
var suffix = (stopIndex >= original.Length) ? string.Empty : original.Substring(stopIndex + 1);
37-
38-
if(original.Substring(startIndex, stopIndex - startIndex + 1).IndexOf(toReplace) != 0)
39-
{
40-
return original;
41-
}
42-
43-
return prefix + toReplace.Replace(toReplace, replacement) + suffix;
34+
var modifiedContent = original.Remove(startIndex, toReplace.Length);
35+
return modifiedContent.Insert(startIndex, replacement);
4436
}
4537
}
4638
}

0 commit comments

Comments
 (0)