0

Is it possible to use the ternary conditional operator in an interpolated string?
Something like:

printfn $"""This is a string{($", and here's the inner string: {innerString}!" if boolFlag  else "!")}\n"""

1 Answer 1

2

You can use any valid F# expression when using string interpolation, including the if expression. Just use the standard F# way of writing it if <boo> then <e1> else <e2>:

let boolFlag = true
let innerString = "Yo"

printfn $"""This is a string{
  if boolFlag then $", and here's the inner string: {innerString}!" 
  else "!"}\n"""
Sign up to request clarification or add additional context in comments.

1 Comment

thanks - it was totally a typo, I could have figure it out myself, sorry about that. (btw the result is not particularly readable, I don't think I'll use it..)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.