Dollar sign in String in Swift
To include a dollar sign in string in Swift, specify the Unicode value of the dollar sign in the string in Unicode scalar format.
The Unicode scalar value of dollar sign is U+0024. To include this in a string, use the Unicode scalar format as shown in the following code snippet.
</>
Copy
let dollarSign = "\u{24}"
Or you can directly specify the dollar sign in the string literal as shown in the following.
</>
Copy
let price = "$100.00"
Example
In the following example, we shall create a string literal with dollar sign in it, and print it to standard output.
main.swift
</>
Copy
let pricing = "The price is \u{24}100.00."
print(pricing)
Output
Conclusion
In this Swift Tutorial, we learned how to specify dollar sign in a string literal in Swift language, using its Unicode value, with examples.