Thanks to visit codestin.com
Credit goes to github.com

Skip to content

System.FormattableString F# snippets #7728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
open System

let name = "Fred"
// <Snippet9>
String.Format("Name = {0}, hours = {1:hh}", name, DateTime.Now)
// </Snippet9>
|> ignore
10 changes: 10 additions & 0 deletions snippets/fsharp/System/FormattableString/Format/fs.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Compile Include="Composite1.fs" />
</ItemGroup>
</Project>
11 changes: 10 additions & 1 deletion xml/System/FormattableString.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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} }}"
```

]]></format>
</remarks>
</Docs>
Expand Down Expand Up @@ -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}"`.
Expand Down