Navigate back to the homepage

how to split string in react native?

Infinitbility
React Native
June 19th, 2022 · 1 min read

Hi Friends 👋,

Welcome To Infinitbility! ❤️

To split string in react native, just use the split(",") method to split string by comma.

Like the following example, we can split a string with a comma, space, or split every char like the below example.

1"infinitbility,aguidehub".split(","); // ["infinitbility","aguidehub"]
2"infinitbility aguidehub".split(" "); // ["infinitbility","aguidehub"]
3"infinitbility".split(""); // ['i', 'n', 'f', 'i', 'n', 'i', 't', 'b', 'i', 'l', 'i', 't', 'y']

Today, I’m going to show you How do i split strings in react native, as above mentioned here, I’m going to use the split() method to split strings.

Let’s start today’s tutorial how do you split string in react native?

In this example, we will do

  1. Create samples string variable.
  2. Use the split() method for split by space, comma, or every char
  3. Print the Output on the screen
1import React, { useState, useEffect } from 'react';
2import { Text, View, StyleSheet } from 'react-native';
3
4export default function App() {
5 return (
6 <View style={styles.container}>
7 <Text>{JSON.stringify("infinitbility,aguidehub".split(","))}</Text>
8 <Text>{JSON.stringify("infinitbility aguidehub".split(" "))}</Text>
9 <Text>{JSON.stringify("infinitbility".split(""))}</Text>
10 </View>
11 );
12}
13
14const 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: Here we are using the JSON.stringify() method to print output as they are, default it will render the same as the string.

As above mentioned, we are taken the example of a string variable, split by comma, and space, and printed on the screen.

Let’s check the output.

React Native, split string example
React Native, split string example
  • Try it yourself

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.

Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Read React Native Tutorial

Request New Tutorial or Article on mail [email protected]

Guide book

Guidebook: The Javascript Monorepo Photoshop Guide

Tutorials

Categories

More articles from Infinitbility

how to get key and value from json array of object in react native?

Example of to get key and value from json array of object in react native with step by step guide.

June 18th, 2022 · 1 min read

how to remove the last character from a string in react native?

Example of to remove the last character from a string in react native with step by step guide.

June 18th, 2022 · 1 min read
© 2020–2022 Infinitbility
About
Link to $https://medium.com/infinitbilityLink to $https://www.facebook.com/InfinitbilityLink to $https://github.com/infinitbilityLink to $https://twitter.com/infinitbilityLink to $https://www.buymeacoffee.com/infinitbilityLink to $mailto:[email protected]