[Everyday C#] - PR 11. String interpolation search split#53991
Draft
BillWagner wants to merge 9 commits into
Draft
[Everyday C#] - PR 11. String interpolation search split#53991BillWagner wants to merge 9 commits into
BillWagner wants to merge 9 commits into
Conversation
Build the projects for this PR.
Build the main articles for this PR.
Move the advanced material into an appropriate language reference article. This information doesn't fit the fundamentals goals, but is important for more advanced developers.
Remove (now) obsolete articles. Add necessary redirects.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR continues the Everyday C# Fundamentals restructuring by moving string-focused how-to content into the new Fundamentals > Strings area, adding a complementary language reference page for advanced string operations, and wiring everything up via TOC updates and redirects.
Changes:
- Adds new Fundamentals articles for string interpolation, searching, and splitting, backed by new
net10.0snippet projects. - Introduces a new language reference page for regex usage, span-based search, and
StringComparisonguidance, plus a new snippet project. - Updates C# TOCs, adds redirects, and removes superseded how-to articles/snippets (and updates the remaining how-to snippets driver).
Reviewed changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| docs/csharp/toc.yml | Adds a new Fundamentals Strings node and removes old string how-to entries. |
| docs/csharp/language-reference/toc.yml | Adds a String operations entry under reference types. |
| docs/csharp/language-reference/builtin-types/string-operations.md | New language reference article consolidating regex, span search, and comparison/perf guidance. |
| docs/csharp/language-reference/builtin-types/snippets/string-operations/string-operations.csproj | New snippet project for the language reference page. |
| docs/csharp/language-reference/builtin-types/snippets/string-operations/Program.cs | Regex and span-search snippet regions for the new language reference page. |
| docs/csharp/fundamentals/strings/interpolation.md | New Fundamentals article for interpolation concepts and common patterns. |
| docs/csharp/fundamentals/strings/search.md | New Fundamentals article for searching strings and choosing comparisons. |
| docs/csharp/fundamentals/strings/split.md | New Fundamentals article for splitting strings with String.Split. |
| docs/csharp/fundamentals/strings/snippets/interpolation/interpolation.csproj | New snippet project for interpolation article examples. |
| docs/csharp/fundamentals/strings/snippets/interpolation/Program.cs | New interpolation snippet regions, including multi-line and constant interpolation examples. |
| docs/csharp/fundamentals/strings/snippets/search/search.csproj | New snippet project for search article examples. |
| docs/csharp/fundamentals/strings/snippets/search/Program.cs | New search snippet regions (Contains, Contains(char), IndexOf/LastIndexOf). |
| docs/csharp/fundamentals/strings/snippets/split/split.csproj | New snippet project for split article examples. |
| docs/csharp/fundamentals/strings/snippets/split/Program.cs | New split snippet regions covering common Split overload patterns. |
| .openpublishing.redirection.csharp.json | Adds redirects from removed how-to pages to new Fundamentals pages. |
| docs/csharp/how-to/snippets/strings/Program.cs | Removes calls to deleted string search/split examples so the project still builds. |
| docs/csharp/how-to/snippets/strings/SearchStrings.cs | Deletes the old how-to search snippet source (migrated). |
| docs/csharp/how-to/snippets/strings/ParseStringsUsingSplit.cs | Deletes the old how-to split snippet source (migrated). |
| docs/csharp/how-to/search-strings.md | Deletes the old how-to article (replaced by Fundamentals + language reference content). |
| docs/csharp/how-to/parse-strings-using-split.md | Deletes the old how-to article (replaced by Fundamentals content). |
Comments suppressed due to low confidence (2)
docs/csharp/language-reference/builtin-types/string-operations.md:10
- The xref
<xref:System.ReadOnlySpan%601>encodes the backtick as%60. Repo guidance in.github/copilot-instructions.mdsays not to encode backticks in API doc IDs; use an unencoded doc ID (or a closed generic likeSystem.ReadOnlySpan{System.Char}) instead.
This article covers string operations that go beyond the everyday `Contains`/`IndexOf`/`Split` methods covered in the Fundamentals [Search strings](../../fundamentals/strings/search.md) and [Split strings into substrings](../../fundamentals/strings/split.md) articles. It focuses on three areas: regular-expression pattern matching, allocation-free search over <xref:System.ReadOnlySpan%601>, and performance considerations for `string` comparison.
docs/csharp/fundamentals/strings/search.md:30
- This sentence says
Contains/StartsWith/EndsWith“default to case-sensitive, ordinal comparison”, butStartsWith(string)/EndsWith(string)default to current-culture semantics unless you passStringComparison. Consider updating the sentence (and potentially the snippet) to encourage using theStringComparisonoverloads when you care about culture/ordinal behavior.
Use `Contains`, `StartsWith`, or `EndsWith` to test for the presence of a substring:
:::code language="csharp" source="snippets/search/Program.cs" id="contains":::
These methods default to **case-sensitive, ordinal** comparison. To accept user input or to ignore case for display text, pass a <xref:System.StringComparison> value such as <xref:System.StringComparison.CurrentCultureIgnoreCase?displayProperty=nameWithType> or <xref:System.StringComparison.OrdinalIgnoreCase?displayProperty=nameWithType>.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Review the major changes and edit / content review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #53553
Phase D, PR 11 of the Everyday C# Fundamentals restructuring (issue #53553). Pull and revise three string articles into the new Fundamentals/Strings section, redistribute deep-cut content to a new Language Reference page, update TOC, and add redirects. Stage commits locally on the existing branch (no PR open).
Primary files to review:
Steps
Phase 1 — New snippet projects (parallel, independent)
docs/csharp/fundamentals/strings/snippets/interpolation/interpolation.csproj—net10.0,OutputType=Exe,ImplicitUsings=enable,Nullable=enable(matchnull-safetyconvention).docs/csharp/fundamentals/strings/snippets/interpolation/Program.cs— port the snippets fromdocs/csharp/tutorials/snippets/StringInterpolation/Program.cswith these adjustments:// <general>,// <format-string>,// <alignment>,// <alignment-and-format>,// <escapes>,// <conditional>,// <culture>,// <invariant>lowercase ids (match repo convention in recent how-to snippets).// <newlines>— multi-line interpolation expression body (C# 11) with{}containing line break and embedded operators.// <constant-interpolated>—const string Greeting = $"Hello, {Audience}!";withconst string Audience = "world";(C# 10).FormattableStringexamples (CultureSensitiveOld,InvariantCultureOld); keep only the modernstring.Createform. Older form belongs instring-operations.mdif needed (decide during writing — likely just dropped per Goal 9: don't tell readers their existing code is broken; older form is still in Language Reference).// => …comments on every output line.docs/csharp/fundamentals/strings/snippets/search/search.csproj— same config.docs/csharp/fundamentals/strings/snippets/search/Program.cs— port only everyday snippets from the existingSearchStrings.cs:<contains>—Contains/StartsWith/EndsWithwithStringComparison.CurrentCultureIgnoreCaseandStringComparison.Ordinaldiscussion in prose.<index-of>—IndexOf/LastIndexOfwith the substring extraction example.Snippet3,Snippet4); they move tostring-operations.md.<contains-char>—Contains(char)overload (one-line, often-missed).docs/csharp/fundamentals/strings/snippets/split/split.csproj— same config.docs/csharp/fundamentals/strings/snippets/split/Program.cs— port from existingParseStringsUsingSplit.cs:<split-words>,<index-words>,<repeated-separators>,<multi-char>,<multi-char-gaps>,<string-separators>,<limit-count>,<trim-entries>.string[] arrayswith collection expressions (["...", "..."]).docs/csharp/language-reference/builtin-types/snippets/string-operations/string-operations.csproj— same config.docs/csharp/language-reference/builtin-types/snippets/string-operations/Program.cs— port the two regex regions fromSearchStrings.cs(<regex-pattern>,<regex-validate>); add a brief<span-search>showingMemoryExtensions.IndexOfoverReadOnlySpan<char>.Phase 2 — New Fundamentals articles (parallel within phase, depend on Phase 1)
Create
docs/csharp/fundamentals/strings/interpolation.md:title,description,ms.date: 05/21/2026,ms.topic: concept-article,ai-usage: ai-assisted.null-safety/index.md) routing newcomers to Get started, experienced devs to Language Reference.:::code language="csharp" source="snippets/interpolation/Program.cs" id="...":::(useidnotIDto match how-to convention).string-operations.mdfor advanced handler/perf content.Create
docs/csharp/fundamentals/strings/search.md:Contains/StartsWith/EndsWith, includingContains(char)) → "Where does the text occur?" (IndexOf/LastIndexOfwith substring extraction) → "Choosing the right comparison" (brief explanation ofStringComparisonordinal vs. current-culture, recommendOrdinalfor invariants andCurrentCultureIgnoreCasefor user-facing searches, with justification per Goal 9).string-operations.md; deeper culture-sensitive comparison → link to existingdocs/standard/base-types/comparing-strings.md.Create
docs/csharp/fundamentals/strings/split.md:Regex.Split" pointer (one sentence, link tostring-operations.md).Phase 3 — Redistributed Language Reference page (depends on Phase 1)
docs/csharp/language-reference/builtin-types/string-operations.md:title: "String operations: pattern matching, performance, and span-based search",ms.topic: reference, noai-usage(Reference content), no F1/helpviewer keywords (those stay onreference-types.md).the/theirexample withRegex.IsMatchfrom currentsearch-strings.md.stringmethods vs. regular expressions — keep the existing tip but expand into a paragraph with guidance: preferstringmethods for known literals and prefixes; use regex for patterns or alternations.ReadOnlySpan<char>— showMemoryExtensions.IndexOfand explain when allocation avoidance matters (high-throughput parsers, hot paths). One short example.StringComparisondefaulting to current culture in older overloads and the cost of culture-sensitive comparison vs.Ordinal.regular-expression-language-quick-reference.md,best-practices-strings.md, fundamentals/strings/search.md, fundamentals/strings/split.md.Phase 4 — TOC updates (depend on Phases 2 & 3)
Modify
docs/csharp/toc.yml:How-to C# articlesnode.Stringsnode in the Fundamentals section, inserted betweenNull safetyandObject-oriented programming(after line 84). Three entries —Interpolation→fundamentals/strings/interpolation.md,Search strings→fundamentals/strings/search.md,Split strings into substrings→fundamentals/strings/split.md. Per Decision (c), do not pre-add PR 10 entries; whoever merges last fixes ordering.Modify
docs/csharp/language-reference/toc.yml:String operationsentry underReference types(around line 60, nearBuilt-in reference types) pointing at./builtin-types/string-operations.md.Phase 5 — Redirects + cleanup (depends on Phase 4)
Modify
.openpublishing.redirection.csharp.json:/docs/csharp/how-to/search-strings.md→/dotnet/csharp/fundamentals/strings/search./docs/csharp/how-to/parse-strings-using-split.md→/dotnet/csharp/fundamentals/strings/split.source_path_from_root).Delete
docs/csharp/how-to/search-strings.mdanddocs/csharp/how-to/parse-strings-using-split.md.Delete
docs/csharp/how-to/snippets/strings/SearchStrings.csanddocs/csharp/how-to/snippets/strings/ParseStringsUsingSplit.cs.Modify
docs/csharp/how-to/snippets/strings/Program.cs— drop theParseStringsUsingSplit.Examples()andSearchStrings.Examples()calls and their banner lines so the project still builds.Phase 6 — Verification
dotnet buildeach new snippet project (interpolation,search,split,string-operations) and the modifiedhow-to/snippets/strings. All must build clean anddotnet runmust produce sane output. Spot-check 2–3 snippet outputs match the trailing// => …comments per Goal 4.git status/git diff --statto confirm the file count is in the ~10-file range expected for PR 11 (snippets + 3 articles + 1 LR article = ~9 files; plus toc/redirects/deletes).copilot-instructions.md).language-reference/tokens/interpolated.md,string-operations.md, etc.) using the existingmarkdown-links-verifier-config.jsonif available, or by visual inspection.(1) snippets,(2) new Fundamentals articles + LR string-operations,(3) toc.yml + language-reference toc.yml,(4) redirects + deletes. (Commit grouping is advisory; user can resequence.)Relevant files
docs/csharp/tutorials/string-interpolation.md— source forinterpolation.md. Stays in place per user's call (PR 12 moves it). Snippet project attutorials/snippets/StringInterpolation/Program.csis the template; copy and modernize.docs/csharp/how-to/search-strings.md— source forsearch.md; delete after pull. Has a typo on line 62 (./snippets/\strings/...) that should not be carried forward.docs/csharp/how-to/parse-strings-using-split.md— source forsplit.md; delete after pull.docs/csharp/how-to/snippets/strings/— shared project; only delete the two relevant.csfiles and adjustProgram.cs.docs/csharp/fundamentals/null-safety/nullable-value-types.mdanddocs/csharp/fundamentals/null-safety/index.md— style/structure templates from PR 8 (frontmatter, tip block, snippet reference style).docs/csharp/fundamentals/null-safety/snippets/nullable-value-types/nullable-value-types.csproj— snippet project template (net10.0, exe).docs/csharp/toc.yml— Fundamentals section ends at line 84 (null-operators); how-to entries to remove are at 336–337 and 340–341.docs/csharp/language-reference/toc.yml— Reference types group is around lines 52–66..openpublishing.redirection.csharp.json— sorted alphabetically bysource_path_from_root; redirects use/dotnet/...URL form (no.md)..github/copilot-instructions.md—ai-usage: ai-assistedrequired on AI-generated content; no F1/helpviewer keywords on Fundamentals articles; snippet block format:::code language="..." source="..." id="...":::..github/instructions/Markdown.WritingStyle.instructions.md— apply when writing the three new articles.Internal previews