Copy link to clipboard
Copied
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
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
Copy link to clipboard
Copied
[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.
Copy link to clipboard
Copied
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')
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
So why you won't use your text, now when you have a code that adds '-' and '.00'?
Copy link to clipboard
Copied
I already ran the code but it didn't work for me
If it doesn't bother you
Tell me how the code works
Copy link to clipboard
Copied
Use for example ExtendScript ToolKit to display the result in its Javascript console, or any other editor that you use to log the result to the console. btw what is your result so far?
Copy link to clipboard
Copied
The picture I attached was for clarification
I want to add - at the beginning of the categories
And the prices are in another text layer I want to add 00
Items in a text layer
And the prices are in another text layer
Copy link to clipboard
Copied
To get changed results from text layers change all '\n' in 'replace' code parts to '\r'.
Copy link to clipboard
Copied
I already used the code and it didn't give me the result
strng = 'rumi\nMix cheese (without '
strng += 'vegetables)\nmeat\n\n10\n15\n20'
strng = strng.replace(/(\d)(\r|$)/g, '$1.00$2')
strng.replace(/(^|\r)([a-z])/ig, '$1-$2')
Copy link to clipboard
Copied
Of course it didn't. Do you see anywhere in the code reference to layers? And why you use the code with defined text that was given to you as an example? Bind it to the text layers content.
Copy link to clipboard
Copied
Dear sir
You are dealing with a person who does not understand the Java language
I resorted to this forum because you are experts in this knowledge
Why don't you offer full assistance if you want to help
You provide a portion of the information and you want me to do the rest while I don't know anything
Why don't you give me the full code and I'll be thankful to you
Copy link to clipboard
Copied
I gave you full code. Read your starting post. There's nothing about how you'd like to use it, like where the text is kept, so whether in layer / file. To make it easier for you I recreated by hand part of text you shared only visually to show you the regex code works indeed. You have asked of generic method to do what requested and I posted it. You shouldn't ask for scripts if you don't know how to use them. First learn how to use scripts, then ask for them.
Copy link to clipboard
Copied
My question in the topic is how to convert the text to the same text, but by adding - at the beginning of each line
Also, if I have a text layer that contains numbers, I want to add 00 at the end of each number
The code you attached, I don't know how to use it
This is just what I wanted
Copy link to clipboard
Copied
The code I shared does exactly that you wanted, adds '-' and '.00' accordingly to letters and numbers.
How that is possible you don't know how to use this code if you already created plenty of scrpting threads of different kind, where asking for harder stuff to do? So maybe tell me how you use this code or any other to display the result. For example, how you would know the result of 2 + 2 code? Where you're going to see that's 4?
From Modify code to enter new text but within the boundaries of the document itself thread you created just few days ago I see you know how to create / access / replace content of text layers, so I'm sure no one has to explain it to you, or else you're not able to remember events from last year, however they happened 2 days ago 😄
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Thank you very much, I modified the code and it was done
Thank you very much for your interest
Copy link to clipboard
Copied
Just for fun:
with(activeDocument.activeLayer.textItem)
contents = contents.replace(/(?:(\d)(\r|$))|(?:(^|\r)([a-z]))/ig,
function(_,v2,v3,v4,v5){return isNaN(_)?v4+'- '+v5:v2+'.00'+v3})
Copy link to clipboard
Copied
if it was possible
This code works with English typing
Is there a code that works with Arabic writing?
Copy link to clipboard
Copied
Well, I found the solution, and this is by chance, not by knowledge
You have replaced [A - Z]
thank you
Copy link to clipboard
Copied
Maybe try this (reading from right side), only for letters layer:
with(activeDocument.activeLayer.textItem)
contents = contents.replace(/.(\r|$)/g, ' -$1')
Copy link to clipboard
Copied
I tried the code and it didn't work
But it works for me after modifying the code in my way, by chance and experience
strng.replace (/ (^ | \ r) ([أ-ي]) / ig، '$ 1 - $ 2')
Copy link to clipboard
Copied
That's good since I had no any text to try on to be sure I'm going in good direction.
Copy link to clipboard
Copied
You can try your code on this text
رومـــــــــــــــــــــي
ميكس جبن (بدون خضراوات)
لحمـــــــــــــــــــــــة
فـــــــــــــــــــــــــراخ
سجــــــــــــــــــــــق
ســـوســــــيــس
بسطــــــــرمـــــة
تـونــــــــــــــــــــــــه
ميكس مدخنات
(سلامى - سموك ترك - بيف مدخن)
ريحانة ( لحمة – سوسيس – بسطرمة )
Also try the modification I made