Navigate back to the homepage

how to handle apostrophe in react native?

Infinitbility
React Native
August 9th, 2022 · 1 min read
how to handle apostrophe in react native?

Hi Friends 👋,

Welcome To Infinitbility! ❤️

To handle apostrophe ( single quote, or double quote ) in react native, use the ( \ ) Escape characters or ( ` ) Template literals it will handle both types quotes single and double.

Let’s see how Escape characters and Template literals will solve the issue.

1let brokenString = 'I'm a broken string';
2
3console.log(brokenString);
4
5// Output
6// unknown: Unexpected token (1:24)
7
8brokenString = 'I\'m a broken string';
9
10console.log(brokenString);
11
12// Output
13// "I'm a broken string"
14
15brokenString = `I'm a "broken" string`;
16
17console.log(brokenString);
18
19// Output
20// `I'm a "broken" string`

Today, I’m going to show you How do I handle apostrophe in react native, as above mentioned, I’m going to use the above-mentioned ( \ ) Escape characters or ( ` ) Template literals.

Let’s start today’s tutorial how do you handle apostrophe in react native?

React native handle apostrophe example using Escape characters

Here, we will take sample string with quote and will use Escape characters to handle quote in string.

1import React, { useState, useEffect } from "react";
2import { Text, View } from 'react-native';
3export default function App() {
4 const [str, setStr] = useState("");
5
6 useEffect(() => {
7 setStr('I\'m a \"broken\" string');
8 }, []);
9
10 return (
11 <View>
12 <Text>{str}</Text>
13 </View>
14 );
15}

Output

React Native, handle quotes example
React Native, handle quotes example

Try it yourself

React native handle apostrophe example using Template literals

Here, we will take sample string with quote and will use Template literals to handle quote in string.

1import React, { useState, useEffect } from "react";
2import { Text, View } from 'react-native';
3export default function App() {
4 const [str, setStr] = useState("");
5
6 useEffect(() => {
7 setStr(`I'm a "broken" string`);
8 }, []);
9
10 return (
11 <View>
12 <Text>{str}</Text>
13 </View>
14 );
15}

Output

React Native, handle quotes example
React Native, handle quotes example

Try it yourself

In the above example, I have put the example to use escape characters and template literals in react native.

I hope it helps 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 handle apostrophe in typescript?

how to handle apostrophe in typescript?

An example of handle apostrophe in typescript with the step-by-step guide.

August 9th, 2022 · 1 min read
how to check nan in react js?

how to check nan in react js?

An example of check or handle nan in react js with the step-by-step guide.

August 8th, 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]