/    Sign up×
Bounties /Pin to ProfileBookmark

Text Manipulation; toggle punctuation on and off

I’m doing a bible project and I want to be able to toggle punctuation on and off for a whole chapter.

https://www.anothenservices.com/acts/01.htm  for this one I manually removed all of the punctuation, chapters and verses. How do I make it toggle on and off?

to post a answer
CSSHTMLJavaScriptPHP

2 Replies

Davinci•003 auto-replyYou can use JavaScript to toggle punctuation on and off in a text. Here's a simple function that does this:

``javascript
function togglePunctuation(text, isPunctuationOn) {
if (isPunctuationOn) {
return text;
} else {
return text.replace(/[.,/#!$%^&*;:{}=-_
~()]/g,"");
}
}
``

This function takes two parameters: the text you want to manipulate and a boolean indicating whether punctuation should be on or off. If
isPunctuationOn is true, the function returns the text as is. If isPunctuationOn is false, the function removes all punctuation from the text using a regular expression and the replace method.

Here's how you can use this function:

`javascript
let text = "Hello, world!";
console.log(togglePunctuation(text, true)); // Outputs: "Hello, world!"
console.log(togglePunctuation(text, false)); // Outputs: "Hello world"
``

Please note that this function only removes the most common punctuation marks. If you need to remove other punctuation marks, you can add them to the regular expression.

Was this helpful?

Copy linkTweet thisAlerts:
@anothenauthorJan 06.2024 — javascript
function togglePunctuation(text, isPunctuationOn) {
if (isPunctuationOn) {
return text;
} else {
return text.replace(/[.,/#!$%^&*;:{}=-_~()]/g,"");
}
}

javascript
let text = "Hello, world!";
console.log(togglePunctuation(text, true)); // Outputs: "Hello, world!"
console.log(togglePunctuation(text, false)); // Outputs: "Hello world"

Okay, this makes sense.
Is there a limit to the amount of text for " let text = '(large amount of text)' " ?
×

Success!

Help @anothen spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.1,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...