From 4586246e3f3e3a70473f5e39ec4bef8c26d5034a Mon Sep 17 00:00:00 2001 From: albert-du <52804499+albert-du@users.noreply.github.com> Date: Tue, 15 Feb 2022 19:07:17 -0800 Subject: [PATCH] FormattableString F# snippets --- .../System/FormattableString/Format/Composite1.fs | 7 +++++++ .../fsharp/System/FormattableString/Format/fs.fsproj | 10 ++++++++++ xml/System/FormattableString.xml | 11 ++++++++++- 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 snippets/fsharp/System/FormattableString/Format/Composite1.fs create mode 100644 snippets/fsharp/System/FormattableString/Format/fs.fsproj diff --git a/snippets/fsharp/System/FormattableString/Format/Composite1.fs b/snippets/fsharp/System/FormattableString/Format/Composite1.fs new file mode 100644 index 00000000000..7f43780b2bf --- /dev/null +++ b/snippets/fsharp/System/FormattableString/Format/Composite1.fs @@ -0,0 +1,7 @@ +open System + +let name = "Fred" +// +String.Format("Name = {0}, hours = {1:hh}", name, DateTime.Now) +// +|> ignore \ No newline at end of file diff --git a/snippets/fsharp/System/FormattableString/Format/fs.fsproj b/snippets/fsharp/System/FormattableString/Format/fs.fsproj new file mode 100644 index 00000000000..a37d9721f36 --- /dev/null +++ b/snippets/fsharp/System/FormattableString/Format/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/xml/System/FormattableString.xml b/xml/System/FormattableString.xml index 984403fe20c..7b56f591d43 100644 --- a/xml/System/FormattableString.xml +++ b/xml/System/FormattableString.xml @@ -166,18 +166,26 @@ ### Remarks -This static method may be imported in C# by: +This static method may be imported in C# or F# by: ```csharp using static System.FormattableString; ``` +``fsharp + open type System.FormattableString +``` + Within the scope of that import directive, an interpolated string may be formatted in the current culture by writing, for example: ```csharp CurrentCulture($"{{ lat = {latitude}; lon = {longitude} }}"); ``` +```fsharp + CurrentCulture $"{{ lat = {latitude}; lon = {longitude} }}" +``` + ]]> @@ -223,6 +231,7 @@ Within the scope of that import directive, an interpolated string may be formatt A composite format string consists of zero or more runs of fixed text intermixed with one or more format items, which are indicated by an index number delimited with brackets (for example, `{0}`). The index of each format item corresponds to an argument in an object list that follows the composite format string. For example, in the following statement: :::code language="csharp" source="~/snippets/csharp/System/FormattableString/Format/Composite1.cs" id="Snippet9"::: + :::code language="fsharp" source="~/snippets/fsharp/System/FormattableString/Format/Composite1.fs" id="Snippet9"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Formatting.Composite/vb/Composite1.vb" id="Snippet9"::: the composite format string is `"Name = {0}, hours = {1:hh}"`.