Skip to main content
Mohamed Hameed21513110
Inspiring
January 1, 2022
Answered

Adding “-” or any symbol at the beginning of each line .. and adding “00” for each price

  • January 1, 2022
  • 4 replies
  • 2309 views

I have a price list that contains many lines
I want a code that adds "-" or any symbol at the beginning of each line
Also, I want to add "00" at the end of each item price
I have attached pictures that show what I want before and after

This topic has been closed for replies.
Correct answer Kukurykus

This code that I shared in the article I found in one of the forums and it is writing a new text layer
But I am talking about a text layer that is already written and I want to add a certain symbol to it at the beginning of each line
Is this difficult for you to help me?


Is it hard just to look into official documentation? Changing content of text layer is shown there in very friendly manner. Anyway, this is where from / to you get the text content:

 

strng = activeDocument.activeLayer.textItem.contents
/*the code to replace strng content to desired one*/
activeDocument.activeLayer.textItem.contents = strng

 

4 replies

Stephen Marsh
Community Expert
Community Expert
January 1, 2022

@Mohamed Hameed21513110 – providing a layered PSD would be more helpful.

 

What you are looking for, which has been provided by Kukurykus is a "Regular Expression" text pattern search/replace. Google the term "Regular Expression" for more info (sometimes called regex or regexp or grep, among others). This is a huge topic in and of itself, outside of Photoshop or scripting. I personally believed that learning Regular Expressions was so important to many general areas of computing, that I taught myself regex before starting the learning process of scripting Adobe apps.

 

You have two separate text patterns to find/replace.

 

1) Any of multiple text lines that begins with a non-digit character, replace/insert with a hyphen or other character

2) Find any of multiple text lines that begin with only two digits (but possibly 1 or 3 or more?) with no other non-digit characters and then add .00 at the end

 

There are multiple valid regular expression search/replace combinations that will lead to the same result, this is part of the joy of regex!

 

Dave Creamer of IDEAS
Community Expert
Community Expert
January 1, 2022

Do you have to do the text in Photoshop? 

 

It would be much easier to do in InDesign: place you PS image and type/import the text there.

 

The first section can be a bullet list (bullets can be any character).

The second section can be a GREP Find/Change.

 

David Creamer: Community Expert (ACI and ACE 1995-2023)
Kukurykus
Legend
January 1, 2022
strng = 'rumi\nMix cheese (without '
strng += 'vegetables)\nmeat\n\n10\n15\n20'
strng = strng.replace(/(\d)(\n|$)/g, '$1.00$2')
strng.replace(/(^|\n)([a-z])/ig, '$1-$2')
Mohamed Hameed21513110
Inspiring
January 1, 2022

@Kukurykus 

I see you have defined the code according to the written elements
But I want the code to work on any elements
And I want a code that adds "00" to the end of the line at prices

Kukurykus
Legend
January 1, 2022

So why you won't use your text, now when you have a code that adds '-' and '.00'?

Dave Creamer of IDEAS
Community Expert
Community Expert
January 1, 2022

[Edited] Sorry--I noticed this was in the Photoshop forum.

 

You should consider doing the type in another program. I would use InDesign--place the Photoshop file into ID and create/import your text. 

David Creamer: Community Expert (ACI and ACE 1995-2023)