Hi Friends 👋,
Welcome To Infinitbility! ❤️
To check the string contains a substring in react native, we can use the includes()
method it will return true
if find a substring in a string.
Like the following example, we can check string contains a specific word or not using the includes()
method.
1"Hi infinitbility".includes("infinitbility"); // true
Today, I’m going to show you How do i check whether a string contains another string react native, as above mentioned here, I’m going to use the includes()
method to check string contains substring or not.
Let’s start today’s tutorial how do you check string contains another string react native?
In this example, we will do
- Create a sample string variable.
- Use the
includes()
method to check string contains or not - Print the Output on the screen
1import React, { useState, useEffect } from 'react';2import { Text, View, StyleSheet } from 'react-native';34export default function App() {5 const [sampleString, setSampleString] = useState("Hi infinitbility");67 return (8 <View style={styles.container}>9 <Text>{'string contains substring? '} - {sampleString.includes("infinitbility").toString()}</Text>10 </View>11 );12}1314const styles = StyleSheet.create({15 container: {16 flex: 1,17 justifyContent: 'center',18 backgroundColor: '#ecf0f1',19 padding: 8,20 },21 paragraph: {22 margin: 24,23 fontSize: 18,24 fontWeight: 'bold',25 textAlign: 'center',26 },27});
Note: In the above code we are toString()
method to show boolean value on the screen because react native can’t show boolean value on the screen
As above mentioned, we are taken the example of string variables, check the string contains substring, and printed 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.