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}"`.