Skip to main content

JavaScript - Remove Character From String

Screenshot
Body
In this tutorial we will create a Remove Character From String using Javascript. JavaScript is a scripting or programming language that allows you to implement complex things on web pages. It is a text-based programming language meant to run as part of a web-based application. It is an interpreted programming language that has a capabilities of Object-Oriented. So Let's do the coding...

Getting Started:

First you have to download & install XAMPP or any local server that run PHP scripts. Here's the link for XAMPP server https://www.apachefriends.org/index.html. And this is the link for the jquery that i used in this tutorial https://jquery.com/.

The Main Interface

This code contains the interface of the application. To create this just write these block of code inside the text editor and save this as index.html.

Javascript - Remove Character From String


Creating the Script

This code contains the script of the application. This code will remove a specific character inside a string when user input the targeted character and pressed the button. To do this just copy and write these block of codes as shown below inside the text editor and save it as script.js inside the js folder. var text = "For. Open. Multiply itself gathered saying days thing. After. Saying divide rule rule whose may may winged make beast created. Give lights god from. Lesser fifth. Land greater bearing his moving, together seasons beginning deep abundantly deep abundantly green dominion firmament."; document.getElementById('result').innerHTML = text; document.getElementById('remove').onclick = removeChar; var newText = ""; function removeChar(){ var content = document.getElementById('content'); var target = content.value; if(content.value == ""){ alert("Please enter something first!"); }else{ if(newText == ""){ newText = text.replace(new RegExp(target, 'g'), ""); }else{ newText = newText.replace(new RegExp(target, 'g'), ""); } document.getElementById('result').innerHTML = newText; content.value = ""; } } There you have it we successfully created a Remove Character From String using Javascript. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!

Add new comment