I have an array with objects inside of it, a few of the objects contain an underscore in the string.
Example:
{"name": "My_name"}  But I'm calling the name function in multiple places, one such place is in an image tag where the underscore is necessary, using JavaScript I want to select a certain div with the name in it and replace the underscore with space.
Example:
<div>  <div class="name">   My_name  </div>  <img src="My_name.jpg"/> </div>  In the div.name I want it to say My name instead of My_name.
Press Ctrl + H to display the Find and Replace dialog box. You can also click the Home tab in the Ribbon and select Replace in the Find & Select group. In the Find what box, type a space. In the Replace with box, type an underscore, dash, or other value.
To replace underscores with spaces in Python:Use the str. split() method to split the string on each underscore. Call the join() method on a string containing a space. The join method will join the words with a space separator.
You can use the string lstrip() function to remove leading underscores from a string in Python. The lstrip() function is used to remove characters from the start of the string and by default removes leading whitespace characters.
You can replace all underscores in a string with a space like so:
str.replace(/_/g, ' ');  So just do that before the content is put in. If you need to perform the replacement afterwards, loop using each:
$('.name').each(function () {     this.textContent = this.textContent.replace(/_/g, ' '); }); 
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With