Advertisement
Guest User

Untitled

a guest
May 20th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. private static void Main(string[] args)
  2. {
  3. string source = "span like types are awesome!";
  4. // source.ToMemory() converts source from string to ReadOnlyMemory<char>,
  5. // and MemoryMarshal.AsMemory converts ReadOnlyMemory<char> to Memory<char>
  6. // so you can modify the elements.
  7. TitleCase(MemoryMarshal.AsMemory(source.AsMemory()));
  8. // You get "Span like types are awesome!";
  9. Console.WriteLine(source);
  10. }
  11.  
  12. private static void TitleCase(Memory<char> memory)
  13. {
  14. if (memory.IsEmpty)
  15. {
  16. return;
  17. }
  18.  
  19. ref char first = ref memory.Span[0];
  20. if (first >= 'a' && first <= 'z')
  21. {
  22. first = (char)(first - 32);
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement