Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

F# string formatting - using the same value twice

Tags:

f#

c#-to-f#

I am trying to find the F# equivalent of the following C# snippet

string.Format("A: {0} B: {1} A again: {0} C: {2}", a, b, c);

I can do this with:

sprintf "A: %s B: %s A again: %s C: %s" a b a c

However, I am wondering if there is any way to reference the a property twice like in the C# example.

Thanks

like image 713
Macs Dickinson Avatar asked Mar 28 '13 23:03

Macs Dickinson


1 Answers

Fortunately String.Format still works in F#.

> open System;;
> String.Format("Hello {0} {0}", "world");;
val it : string = "Hello world world"
like image 97
N_A Avatar answered Sep 20 '22 14:09

N_A