Get Substring after Specific Character in React JS?

Nov 02, 2022 . Admin

Hello Friends,

In this tutorial, you will learn to get substring after a specific character in react js. This tutorial will give you a simple example of get a substring after a specific character using react js. if you want to see an example of react js get substring after a specific character then you are the right place. let’s discuss react js get substring after specific character example.

In this example get substring after specific character in react js. I will step by step get a substring after a specific character using substring().

So, let's start following example:

Step 1: Create React JS App

In this step, open your terminal and execute the following command on your terminal to create a new react app:

npx create-react-app reactjs-my-example
Step 2: Create index.js file src/index.js
import React from 'react';
import ReactDOM from 'react-dom/client';

const str = 'This is very_long string';

const newStr = str.substring(str.indexOf('_') + 1);

const App = () => {
    
    return (
        <div>
            <h1>{newStr}</h1>
        </div>
    );
}
  
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<App />);
Run React JS App:
npm start

Output:

long string

I hope it can help you...

#React JS