Hi Friends 👋,
Welcome To Infinitbility! ❤️
To replace a string in react native, just use the replace()
method for replacing the first occurrence and replaceAll()
for replacing all occurrences.
Like the following example, we can replace a string with any string or empty ( blank ).
1"Hello Infinitbility".replace("Hello", "Hi"); // 'Hi Infinitbility'2"Hello Infinitbility".replaceAll("i", "-"); // 'Hello Inf-n-tb-l-ty'
Today, I’m going to show you How do i replace strings in react native based on their occurrence, as above mentioned here, I’m going to use the replace()
and replaceAll()
method for replacing strings.
Let’s start today’s tutorial how do you replace a string in react native?
In this example, we will replace a string in a text component ( in a render method ).
Let’s write code…
1import React, { useState, useEffect } from 'react';2import { Text, View, StyleSheet } from 'react-native';34export default function App() {5 const [string, setString] = useState("Hello Infinitbility");67 return (8 <View style={styles.container}>9 <Text>{string.replace("Hello", "Hi")}</Text>10 <Text>{string.replaceAll("i", "-")}</Text>11 </View>12 );13}1415const styles = StyleSheet.create({16 container: {17 flex: 1,18 justifyContent: 'center',19 backgroundColor: '#ecf0f1',20 padding: 8,21 },22 paragraph: {23 margin: 24,24 fontSize: 18,25 fontWeight: 'bold',26 textAlign: 'center',27 },28});
As mentioned above, we are taken the example of a replace string, use the replace()
and replaceAll()
method in react native render, and printed it on the screen.
Let’s check the output.

I hope it’s help you, All the best 👍.
Follow me on Twitter
Join our email list and get notified about new content
No worries, I respect your privacy and I will never abuse your email.
Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.