Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions .replaycheck/docs/csharp/how-to/parse-strings-using-split.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# %version 1
contentPath: docs\csharp\how-to\parse-strings-using-split.md

steps:
- task: RunCodeSnippetReference@1
environment:
type: dotnet-try
outputValidationRules:
- operator: contains
value: <The>
- operator: contains
value: <quick>
- operator: contains
value: <brown>
- operator: contains
value: <fox>
- operator: contains
value: <jumps>
- operator: contains
value: <over>
- operator: contains
value: <the>
- operator: contains
value: <lazy>
- operator: contains
value: <dog.>
uid: 54d6d90f
- task: RunCodeSnippetReference@1
environment:
type: dotnet-try
outputValidationRules:
- operator: contains
value: <The>
- operator: contains
value: <quick>
- operator: contains
value: <brown>
- operator: contains
value: <fox>
- operator: contains
value: <jumps>
- operator: contains
value: <over>
- operator: contains
value: <>
- operator: contains
value: <the>
- operator: contains
value: <lazy>
- operator: contains
value: <dog.>
uid: 56bddea1
- task: RunCodeSnippetReference@1
environment:
type: dotnet-try
outputValidationRules:
- operator: contains
value: "Original text: 'one"
- operator: contains
value: "two three:four,five six seven'"
- operator: contains
value: "7 words in text:"
- operator: contains
value: "<one>"
- operator: contains
value: "<two>"
- operator: contains
value: "<three>"
- operator: contains
value: "<four>"
- operator: contains
value: "<five>"
- operator: contains
value: "<six>"
- operator: contains
value: "<seven>"
uid: cd358438
- task: RunCodeSnippetReference@1
environment:
type: dotnet-try
outputValidationRules:
- operator: contains
value: "Original text: 'one"
- operator: contains
value: "two :,five six seven'"
- operator: contains
value: "7 words in text:"
- operator: contains
value: "<one>"
- operator: contains
value: "<two>"
- operator: contains
value: "<>"
- operator: contains
value: "<five>"
- operator: contains
value: "<six>"
- operator: contains
value: "<seven>"
uid: c6bd73cc
- task: RunCodeSnippetReference@1
environment:
type: dotnet-try
outputValidationRules:
- operator: contains
value: "3 substrings in text:"
- operator: contains
value: "one"
- operator: contains
value: "two"
- operator: contains
value: "three<four"
uid: de9a9fb3
5 changes: 5 additions & 0 deletions docs/csharp/how-to/parse-strings-using-split.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ to split strings on other specific characters or strings.

The following code splits a common phrase into an array of strings for each word.

<!-- replaycheck-task id="54d6d90f" -->
:::code language="csharp" interactive="try-dotnet-method" source="../../../samples/snippets/csharp/how-to/strings/ParseStringsUsingSplit.cs" id="Snippet1":::

Every instance of a separator character produces a value in the
returned array. Consecutive separator characters produce the empty string
as a value in the returned array. You can see how an empty string is created in the following example,
which uses the space character as a separator.

<!-- replaycheck-task id="56bddea1" -->
:::code language="csharp" interactive="try-dotnet-method" source="../../../samples/snippets/csharp/how-to/strings/ParseStringsUsingSplit.cs" id="Snippet2":::

This behavior makes it easier for formats like comma-separated values (CSV)
Expand All @@ -41,14 +43,17 @@ the result sequence.
The following example uses spaces, commas, periods, colons, and tabs as separating characters, which are passed to <xref:System.String.Split%2A> in an array.
The loop at the bottom of the code displays each of the words in the returned array.

<!-- replaycheck-task id="cd358438" -->
:::code language="csharp" interactive="try-dotnet-method" source="../../../samples/snippets/csharp/how-to/strings/ParseStringsUsingSplit.cs" id="Snippet3":::

Consecutive instances of any separator produce the empty string in the output array:

<!-- replaycheck-task id="c6bd73cc" -->
:::code language="csharp" interactive="try-dotnet-method" source="../../../samples/snippets/csharp/how-to/strings/ParseStringsUsingSplit.cs" id="Snippet4":::

<xref:System.String.Split%2A?displayProperty=nameWithType> can take an array of strings (character sequences that act as separators for parsing the target string, instead of single characters).

<!-- replaycheck-task id="de9a9fb3" -->
:::code language="csharp" interactive="try-dotnet-method" source="../../../samples/snippets/csharp/how-to/strings/ParseStringsUsingSplit.cs" id="Snippet5":::

## See also
Expand Down