Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无法拆分或替换从爱奥尼亚2上的PlayStore产品检索到的字符串_Javascript_Typescript_Ionic2_Google Play_In App Purchase - Fatal编程技术网

Javascript 无法拆分或替换从爱奥尼亚2上的PlayStore产品检索到的字符串

Javascript 无法拆分或替换从爱奥尼亚2上的PlayStore产品检索到的字符串,javascript,typescript,ionic2,google-play,in-app-purchase,Javascript,Typescript,Ionic2,Google Play,In App Purchase,我有一个离子2应用程序,允许用户使用订阅 我需要削减从Play store检索到的每个产品的价格,因为Play store以字符串格式返回价格,而不是单独返回 apppurchases中的插件有一个getProducts()方法,该方法接收一个带有需要检索的产品id的字符串数组,并返回一个包含产品的对象数组: this.inAppPurchase.getProducts(this.productIds) .then((products) => {

我有一个离子2应用程序,允许用户使用订阅

我需要削减从Play store检索到的每个产品的价格,因为Play store以字符串格式返回价格,而不是单独返回

apppurchases中的插件有一个
getProducts()
方法,该方法接收一个带有需要检索的产品id的字符串数组,并返回一个包含产品的对象数组:

this.inAppPurchase.getProducts(this.productIds)
            .then((products) => {
            });
嗯,产品是有一个叫做价格的东西。这个价格不是一个数字,而是一个字符串。所以我需要分离货币的价格,唯一的方法是在它们拥有的第一个空间中剪切这些字符串

但问题是如此罕见,因为如果我试图切断Google play检索到我的字符串,我就不能

let productPrice = retrievedProduct.price; //this is the atribute price from each product object

console.log("From play store: " + productPrice); //From play store: US$ 35,88
console.log("Type: " + typeof productPrice); //Type: string
console.log("Length: " + productPrice.length); //Length: 9  
let priceWithoutCurrency = productPrice.substr(productPrice.indexOf(' ') + 1);
console.log("Delete currency with google play product: " + priceWithoutCurrency); //Delete currency with google play product: US$ 35,88

let retrievedPrice = "US$ 35,88";
let priceWithoutCurrency2 = retrievedPrice.substr(retrievedPrice.indexOf(' ') + 1);
console.log("----------------");
console.log("From mock: " + retrievedPrice); //From mock: US$ 35,88  
console.log("Type: " + typeof retrievedPrice); // Type: string  
console.log("Length: " + retrievedPrice.length); //Length: 9
console.log("Delete currency with mock price: " + priceWithoutCurrency2); //Delete currency with mock price: 35,88
您可以看到两个字符串是相等的,它不起作用。 有人知道为什么会这样吗


谢谢你,这太提前了

retrievedProduct.price看起来怎么样?看起来像“US$38,55”,但它取决于设备的语言,例如,在另一台设备中,它看起来像“$38,55”,总是在货币和金额之间有一个空格而不是substr,可以尝试使用string.splice(“”)?如果货币和金额之间总是有空格。然后,您可以将金额检索为字符串[1]。