Shorten string length on label

Hi Everyone,


I'm just started to build my own app, I'm taking the price of a Cryptocurrncy from an API and want to display it on a text label. I have converted into a string which works fine but now I want to shorten the output from 9/10 characters to 6/7 e.g 123456789 to 123456. I can't seem to find a simple solution anywhere.


Anyway I would be grateful for any input, thank you.

If you have a String fullString, just use prefix


let shortString = String(fullString.prefix(6))

I'm taking the price of a Cryptocurrncy from an API and want to display it on a text label.

You should take a look at

NumberFormatter
. This formats numeric values in an international-friendly way, and it offers a bunch of configuration options that make it easy to deal with complex issues. For example, if the price you’re trying to format is stated in terms of some real world currency,
NumberFormatter
has a
.currency
style that you can use for that.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
Shorten string length on label
 
 
Q