Path.TryJoin Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Attempts to concatenate individual path components to a preallocated character span, and returns a value that indicates whether the operation succeeded.
Overloads
TryJoin(ReadOnlySpan<Char>, ReadOnlySpan<Char>, ReadOnlySpan<Char>, Span<Char>, Int32) |
Attempts to concatenate three path components to a single preallocated character span, and returns a value that indicates whether the operation succeeded. |
TryJoin(ReadOnlySpan<Char>, ReadOnlySpan<Char>, Span<Char>, Int32) |
Attempts to concatenate two path components to a single preallocated character span, and returns a value that indicates whether the operation succeeded. |
Remarks
The destination character span must be large enough to hold the concatenated path. You can then retrieve the concatenated path by calling the Span<T>.Slice method, as the following example illustrates.
using System;
using System.IO;
class Program
{
static void Main()
{
int nChars = 0;
var buffer = new Span<Char>(new String(' ', 100).ToCharArray());
var flag = Path.TryJoin("C:/".AsSpan(), "Users/user1".AsSpan(), buffer, out nChars);
if (flag)
Console.WriteLine($"Wrote {nChars} characters: '{buffer.Slice(0, nChars).ToString()}'");
else
Console.WriteLine("Concatenation operation failed.");
}
}
TryJoin(ReadOnlySpan<Char>, ReadOnlySpan<Char>, ReadOnlySpan<Char>, Span<Char>, Int32)
- Source:
- Path.cs
- Source:
- Path.cs
- Source:
- Path.cs
Attempts to concatenate three path components to a single preallocated character span, and returns a value that indicates whether the operation succeeded.
public:
static bool TryJoin(ReadOnlySpan<char> path1, ReadOnlySpan<char> path2, ReadOnlySpan<char> path3, Span<char> destination, [Runtime::InteropServices::Out] int % charsWritten);
public static bool TryJoin (ReadOnlySpan<char> path1, ReadOnlySpan<char> path2, ReadOnlySpan<char> path3, Span<char> destination, out int charsWritten);
static member TryJoin : ReadOnlySpan<char> * ReadOnlySpan<char> * ReadOnlySpan<char> * Span<char> * int -> bool
Public Shared Function TryJoin (path1 As ReadOnlySpan(Of Char), path2 As ReadOnlySpan(Of Char), path3 As ReadOnlySpan(Of Char), destination As Span(Of Char), ByRef charsWritten As Integer) As Boolean
Parameters
- path1
- ReadOnlySpan<Char>
A character span that contains the first path to join.
- path2
- ReadOnlySpan<Char>
A character span that contains the second path to join.
- path3
- ReadOnlySpan<Char>
A character span that contains the third path to join.
- charsWritten
- Int32
When the method returns, a value that indicates the number of characters written to the destination
.
Returns
true
if the concatenation operation is successful; otherwise, false
.
Remarks
destination
must be large enough to hold the concatenated path. You can then retrieve the concatenated path by calling the Span<T>.Slice method, as the example illustrates.
See also
Applies to
TryJoin(ReadOnlySpan<Char>, ReadOnlySpan<Char>, Span<Char>, Int32)
- Source:
- Path.cs
- Source:
- Path.cs
- Source:
- Path.cs
Attempts to concatenate two path components to a single preallocated character span, and returns a value that indicates whether the operation succeeded.
public:
static bool TryJoin(ReadOnlySpan<char> path1, ReadOnlySpan<char> path2, Span<char> destination, [Runtime::InteropServices::Out] int % charsWritten);
public static bool TryJoin (ReadOnlySpan<char> path1, ReadOnlySpan<char> path2, Span<char> destination, out int charsWritten);
static member TryJoin : ReadOnlySpan<char> * ReadOnlySpan<char> * Span<char> * int -> bool
Public Shared Function TryJoin (path1 As ReadOnlySpan(Of Char), path2 As ReadOnlySpan(Of Char), destination As Span(Of Char), ByRef charsWritten As Integer) As Boolean
Parameters
- path1
- ReadOnlySpan<Char>
A character span that contains the first path to join.
- path2
- ReadOnlySpan<Char>
A character span that contains the second path to join.
- charsWritten
- Int32
When the method returns, a value that indicates the number of characters written to the destination
.
Returns
true
if the concatenation operation is successful; otherwise, false
.
Remarks
destination
must be large enough to hold the concatenated path. You can then retrieve the concatenated path by calling the Span<T>.Slice method, as the example illustrates.