How to replace underscores with spaces?
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, ' ');
});
Replacing spaces with underscores in JavaScript?
Try .replace(/ /g,"_");
Edit: or .split(' ').join('_')
if you have an aversion to REs
Edit: John Resig said:
If you're searching and replacing
through a string with a static search
and a static replace it's faster to
perform the action with
.split("match").join("replace") -
which seems counter-intuitive but it
manages to work that way in most
modern browsers. (There are changes
going in place to grossly improve the
performance of .replace(/match/g,
"replace") in the next version of
Firefox - so the previous statement
won't be the case for long.)
Replacing Spaces with Underscores
$name = str_replace(' ', '_', $name);
Replace spaces with a Underscore in a URL
Try using str_replace
for replace space with underscore
<div class="groupinfo">
<a href="<?= base_url() ?>group/group_id/<?= $gr->grp_id ?>/<?= str_replace(" ","_",$gr->grp_name) ?>">
</div>
Replace initial spaces with underscores in Javascript
I want to replace each of the leading spaces with an underscore
To do that with just one replace
call within the current spec,* you'd need the function call version of replace
to do that, creating a string of underscores as long as the matched sequence of spaces:
y = x.replace(/^ +/, function(m) {
return "_".repeat(m.length);
});
or with an ES2015+ arrow function:
y = x.replace(/^ +/, m => "_".repeat(m.length));
Live Example:
const x = " four spaces";const y = x.replace(/^ +/, m => "_".repeat(m.length));console.log(y);
Replace spaces with underscores inside array elements in PySpark
Use highe order functions to replace white space through regexp_replace
schema
root
|-- id: long (nullable = true)
|-- objects: array (nullable = true)
| |-- element: string (containsNull = true)
solution
df.withColumn('concat_obj', expr("transform(objects, x-> regexp_replace(x,' ','_'))")).show(truncate=False)
+---+------------------------------------+------------------------------------+
|id |objects |concat_obj |
+---+------------------------------------+------------------------------------+
|1 |[sun, solar system, mars, milky way]|[sun, solar_system, mars, milky_way]|
|2 |[moon, cosmic rays, orion nebula] |[moon, cosmic_rays, orion_nebula] |
+---+------------------------------------+------------------------------------+
Related Topics
Programmatically Determine Whether to Describe an Object with "A" or "An"
Why Preg_Replace Throws Me a "Unknown Modifier" Error
PHP How to Remove Last Part of a Path
Destroy Session on Window Close
How to Search Array for Multiple Values in PHP
How to Create Clean Url Using .Htaccess
How to Pass an Array of Pdo Parameters Yet Still Specify Their Types
Convert PHP Array String into an Array
Pdo Lastinsertid() Always Return 0
PHP Dynamic Name for Object Property
Sending/Displaying a Base64 Encoded Image