iOS Question [SOLVED] Get ISO-3-Letter Curency codes in In App Purchases and more

hatzisn

Expert
Licensed User
Longtime User
I am able to get the localized price of a product. The fact is that it has two problems.
1st) It appears correctly in the log window but if you look at it in a hex editor you see this:
32 2C 39 39 C2 A0 E2 82 AC

The first four bytes is the price 2,99
The c2 a0 is the space character
I suppose that the E2 82 is the Euro sign and I do not know what the AC is.

2nd) The currency displays its sign for example Euro Sign and not ISO-3-Letter currency code.


How can I get the correct price in a string and the currency in ISO-3-Letter code? F.e. EUR or USD?

Ok, maybe for the price I search for the c2 a0 and take before it the bytes.
I have found this code for the currency ISO-3-Letter code but I am not objective C familiar so I do not know how to implement it.

Objective-C:
NSString *localeId = @"JPY"; //[[NSLocale commonISOCurrencyCodes] objectAtIndex:1];
NSLocale *locale = [NSLocale currentLocale];
NSString *currency = [locale displayNameForKey:NSLocaleCurrencySymbol
                                       value:localeId];
NSLog(@"locale %@ currency %@", localeId, currency);
 
Last edited:

hatzisn

Expert
Licensed User
Longtime User
I got it. Here is the answer:

B4X:
Private Sub GetPriceAndCurrencyISO3LetterCode(LocalizedPrice As String) As String()
    Dim sPrice(2) As String
    Dim bc As ByteConverter
    Dim b2() As Byte = LocalizedPrice.GetBytes("UTF8")
    Dim iUesh As Int
    For ii = 0 To b2.Length - 2
        If b2(ii) = 0xc2 And b2(ii+1) = 0xa0 Then
            iUesh = ii
            Exit
        End If
    Next
    Dim sPriceNum As String = LocalizedPrice.SubString2(0, iUesh)
    
    Dim sPrice3Cur As String '= "EUR"
    Dim nativeMe As NativeObject = Me
    LogColor(nativeMe.RunMethod("get3LetCur", Null).AsString,0xff00ff00)
    sPrice3Cur = nativeMe.RunMethod("get3LetCur", Null).AsString
    
    Return Array As String(sPriceNum, sPrice3Cur)
End Sub

#If OBJC
- (NSString*) get3LetCur {
   NSString *country3LetCur = [[NSLocale currentLocale] objectForKey: NSLocaleCurrencyCode];
   return country3LetCur;
}
#end if
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…