I'd like the use the getSkuDetails()
call from the In-app Billing v3 API to dynamically display a list of inapp purchase options with properly translated titles and relevant price.
However, the "title" property from getSkuDetails() seems to always be of the form "<item title> (app name)"
, which is less than useful. How can I get only the item title itself without the app name without hacking the string?
That is the way it is. I mean even I didn't like it, obviously user knows that he is buying from the app but I think Google is going to reply it in this way only
As no one has replied with an actual regex pattern to match the app name in parentheses in the SKU title I thought I just post the code here for further reference:
// matches the last text surrounded by parentheses at the end of the SKU title val skuTitleAppNameRegex = """(?> \(.+?\))$""".toRegex() val titleWithoutAppName = skuDetails.title.replace(skuTitleAppNameRegex, "")
The regex is as strict as possible to allow for additional text in parentheses within your SKU title without removing it as well (e.g. SKU titles like Premium (Subscription) would stay as they are). The only thing you should avoid is parentheses in your app name, but with a little tweaking of the regex you could work around that as well.
As regexes are notoriously expensive to build it is advisable to store it in a field and avoid constructing them each time over when you are parsing your SKUs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With