.NET Fiddle

CSharp · Console

/Program.cs

using System;
using System.Runtime.InteropServices;
					
public class Program
{
	 public static string Marshal_Span(string Content)
    {
        Span<char> chars = MemoryMarshal.CreateSpan(ref MemoryMarshal.GetReference(Content.AsSpan()), Content.Length);
        for (int i = 0; i < chars.Length; i++)
        {
            if (chars[i] == ' ')
            {
                chars[i] = ',';
            }
        }

        return Content; 
    }
	
	public static void Main()
	{
		string Content =
        "Hello World! Add new line. Ok. Substring allocates a new string object on the heap and performs a full copy of the extracted text." +
        "String manipulation is a performance bottleneck for many programs. Many APIs that accept strings also have overloads that accept a ReadOnlySpan<System.Char> argument." +
        "When such overloads are available, you can improve performance by calling AsSpan instead of Substring.";
    
		Console.WriteLine(Marshal_Span(Content));
	}
}
;