ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

Quote

Add double quotes to the beginning and end of a string. Not taking into account if there are already quotes available.

Source

public static string Quote(this string s)
{
    StringBuilder sb = new StringBuilder();
    sb.Append('"').Append(s).Append('"');
    return sb.ToString();
}

Example

string s = "Hello world";
Console.WriteLine(s.Quote()); // Output: "Hello world"

Author: Patrick

Submitted on: 3 sep. 2020

Language: csharp

Type: string

Views: 3861