• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

405
Views
Why is string.replaceAll() not a function on Android React Native?

I recently stumbled on this issue that, though ran well on iOS, could not run on Android, even though I use the same code base and run them in parallel.

Error log on react native 0.64.4

Note that (number + '') always returns a string, and this code runs on iOS.

Trying the regex with the global flag "g":

string.replace(/searchString/g, replaceString)

like some suggested StackOverFlow answers does not work either.

Can you guys guess the reasons and provide solutions?

almost 3 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Alternative way to do this with the split and join functions.

string.split("searchString").join("replaceString");
almost 3 years ago · Juan Pablo Isaza Report

0

replace method works perfectly in the latest React Native version. Please note you need to use string literals (`) instead of quotes (") for string variables.

string.replace(`/${searchString}/g`, replaceString);

Tested on the following React Native version:

react-native-cli: 2.0.1
react-native: 0.64.3
almost 3 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error