Add additional space to string at every existing space
Copy link to clipboard
Copied
Hello, I'm trying to make a script that edits a layer's text by adding another space at every instance there is already an existing space.
"Edit spaces" to
"Edit spaces"
Any help much appreciated. Thanks in advance!
Explore related tutorials & articles
Copy link to clipboard
Copied
Hi it can be done with Actions you need to record it...Regards
Copy link to clipboard
Copied
How can it be done with an action. Actions can not use logic to retrieve text layers and search for spaces and insert additional spaces. And if you double the amount of spaces how would an action known if the revised text will fit on canvas. How would an action know how many text layer there are or where in the layer stack text layers are. A Photoshop script may be able to do what they want to do. It would not be easy to program such a Photoshop script. If it is not something they would use all the time they would save time manually editing their text layers.
Copy link to clipboard
Copied
in action it colud be done throw find&replace menu of text item
Copy link to clipboard
Copied
Yes you can record find and replace. How well replacing a space with two spaces can get very messy when there are consecutive spaces in the text also expending the length of text with extra spaces can result with text not fitting within the text area verbiage will not be displayed in the document. IMO Find and replace should be used manually not in an action. Text can be quite complex to the deal with in automation it above my pay grade.
.
Copy link to clipboard
Copied
You can use Google search to search for scripts poster on this site for editing text layers. Some have been posted. This site search is useless for searching for things like that. Use Google.
Copy link to clipboard
Copied
Try this:
var textI = app.activeDocument.activeLayer.textItem
textI.contents = textI.contents.replace(/ /g," ");
Copy link to clipboard
Copied
Hmm, this is seemingly exactly what I want, however, doesn't seem to be working for me. Did this actually work for you? Something that's interesting is I copy/pasted the below code from my file, and the number of spaces between the " " pasted as only one, despite in the code having several. Curious..
var myText = doc.activeLayer.textItem
myText = myText.contents.replace(/ /g," ");
Copy link to clipboard
Copied
You only have one space between the quotes, you need two. What you are doing is replacing a single space with another single space.
Copy link to clipboard
Copied
Chuck, that's what I'm saying. It pasted here with only 1 space but in my actual code there are several. This is what makes me wonder if this method indeed works. Thanks
Copy link to clipboard
Copied
Do you only have one space between the forward slashes - / /, and two spaces between the quotes - " "? It's working fine for me.
Copy link to clipboard
Copied
"Edit spaces" to
"Edit spaces"
It sounds like you are trying to get more word spacing? If that's the case it would be easier to manipulate the word spacing via the Paragraph Style.
So the default Word Spacing is 80 |100 |133
You can increase the Word Spacing and keep the same Letter Spacing:

