Skip to content

Instantly share code, notes, and snippets.

@kuhlenh
Last active November 20, 2017 16:53
Show Gist options
  • Save kuhlenh/4d85c9a58f9f15e3f8c19bc35d34051e to your computer and use it in GitHub Desktop.
Save kuhlenh/4d85c9a58f9f15e3f8c19bc35d34051e to your computer and use it in GitHub Desktop.
Example from Span<T> in CoreCLR
ReadOnlySpan<char> valueSpan = value.AsReadOnlySpan();
if (!Int32.TryParse(valueSpan.Slice(0, 4), NumberStyles.None, NumberFormatInfo.InvariantInfo, out year) ||
!Int32.TryParse(valueSpan.Slice(5, 2), NumberStyles.None, NumberFormatInfo.InvariantInfo, out month) ||
!Int32.TryParse(valueSpan.Slice(8, 2), NumberStyles.None, NumberFormatInfo.InvariantInfo, out day))
{
// Couldn't convert integer, fail
return null;
}
// see entire example : https://github.com/dotnet/coreclr/blob/a16fdf04c50fd7b14b939835a040bd21084f1dc4/src/mscorlib/shared/System/Globalization/JapaneseCalendar.Win32.cs#L162-L165
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment