Skip to content

Commit fba1061

Browse files
committed
Fixed replace logic
1 parent a139d74 commit fba1061

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/LinkDotNet.StringBuilder/ValueStringBuilder.Replace.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public void Replace(scoped ReadOnlySpan<char> oldValue, scoped ReadOnlySpan<char
141141
if (delta < 0)
142142
{
143143
newValue.CopyTo(buffer[index..]);
144-
Remove(index + 1, -delta);
144+
Remove(index + newValue.Length, -delta);
145145
}
146146

147147
// Same length -> We can just replace the memory slice

tests/LinkDotNet.StringBuilder.UnitTests/ValueStringBuilder.Replace.Tests.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@ public void ShouldReplaceAllText()
5757
builder.ToString().Should().Be("Hallöchen World. How are you doing. Hallöchen world examples are always fun.");
5858
}
5959

60+
[Fact]
61+
public void ShouldReplacePart()
62+
{
63+
using var builder = new ValueStringBuilder("Hello World");
64+
65+
builder.Replace("Hello", "Ha");
66+
67+
builder.ToString().Should().Be("Ha World");
68+
}
69+
6070
[Theory]
6171
[InlineData("", "word")]
6272
[InlineData("word", "")]

0 commit comments

Comments
 (0)