Skip to content

Remove the last character of a string: net10.0 retarget, range and StringBuilder.Remove benchmarks, emoji-safe helper - #2202

Merged
vladimir-pecanac-main merged 2 commits into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/113414-csharp-fastest-way-to-remove-the-last-character-of-a-string
Sep 17, 2026
Merged

vladimir-pecanac-main merged 2 commits into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/113414-csharp-fastest-way-to-remove-the-last-character-of-a-string

Conversation

@vladimir-pecanac-main

Copy link
Copy Markdown
Collaborator

Updates the strings-csharp/RemoveLastCharOfAString sample alongside a rewrite of the matching article.

  • Both projects retargeted from net8.0 to net10.0.
  • BenchmarkDotNet 0.13.12 to 0.15.8; Microsoft.NET.Test.Sdk 18.10.0, MSTest 4.4.0, coverlet.collector 10.0.1.
  • Adds RemoveLastCharUsingRange, so the inputString[..^1] expression the article prints is measured like the rest.
  • Adds RemoveLastCharUsingStringBuilderRemove, the sb.Remove(sb.Length - 1, 1) form.
  • Renames RemoveLastCharUsingStringBuilder to RemoveLastCharUsingStringBuilderLength, so the two StringBuilder rows in the results table say which is which.
  • Adds RemoveLastTextElement, a text-element aware helper that removes a whole character rather than a single char, so a string ending in an emoji does not lose half a surrogate pair.
  • Three new tests, nine in total. Build clean, all tests passing on .NET 10.0.10.

…uilder.Remove benchmarks, add text-element helper

- Retarget both projects from net8.0 to net10.0
- BenchmarkDotNet 0.13.12 to 0.15.8
- Test.Sdk 18.10.0, MSTest 4.4.0, coverlet.collector 10.0.1
- Add RemoveLastCharUsingRange and RemoveLastCharUsingStringBuilderRemove benchmarks
- Rename RemoveLastCharUsingStringBuilder to RemoveLastCharUsingStringBuilderLength
- Add RemoveLastTextElement, an emoji-safe removal helper
- Three new tests, nine in total
@vladimir-pecanac-main
vladimir-pecanac-main merged commit 0795220 into CodeMazeBlog:main Sep 17, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant