• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Enthusiast ,
Jan 01, 2022 Jan 01, 2022

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

0005.jpg

TOPICS
Actions and scripting , SDK

Views

1.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jan 01, 2022 Jan 01, 2022

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

 

Votes

Translate

Translate
Adobe
Community Expert ,
Jan 01, 2022 Jan 01, 2022

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. 

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 01, 2022 Jan 01, 2022

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')

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 01, 2022 Jan 01, 2022

Copy link to clipboard

Copied

@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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 01, 2022 Jan 01, 2022

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 01, 2022 Jan 01, 2022

Copy link to clipboard

Copied

@Kukurykus 

I already ran the code but it didn't work for me
If it doesn't bother you
Tell me how the code works

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 01, 2022 Jan 01, 2022

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 01, 2022 Jan 01, 2022

Copy link to clipboard

Copied

@Kukurykus 

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

0005.jpg

Items in a text layer
And the prices are in another text layer

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 01, 2022 Jan 01, 2022

Copy link to clipboard

Copied

To get changed results from text layers change all '\n' in 'replace' code parts to '\r'.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 01, 2022 Jan 01, 2022

Copy link to clipboard

Copied

@Kukurykus 

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')

لقطة الشاشة 2022-01-01 212253.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 01, 2022 Jan 01, 2022

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 01, 2022 Jan 01, 2022

Copy link to clipboard

Copied

@Kukurykus 

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 01, 2022 Jan 01, 2022

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 01, 2022 Jan 01, 2022

Copy link to clipboard

Copied

@Kukurykus 

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 01, 2022 Jan 01, 2022

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 😄

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 01, 2022 Jan 01, 2022

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 01, 2022 Jan 01, 2022

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

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 01, 2022 Jan 01, 2022

Copy link to clipboard

Copied

@Kukurykus 

Thank you very much, I modified the code and it was done
Thank you very much for your interest

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 01, 2022 Jan 01, 2022

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})

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 01, 2022 Jan 01, 2022

Copy link to clipboard

Copied

@Kukurykus 

if it was possible
This code works with English typing
Is there a code that works with Arabic writing?

لقطة الشاشة 2022-01-01 231513.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 01, 2022 Jan 01, 2022

Copy link to clipboard

Copied

@Kukurykus 

Well, I found the solution, and this is by chance, not by knowledge

You have replaced [A - Z]
thank you

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 01, 2022 Jan 01, 2022

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')

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 01, 2022 Jan 01, 2022

Copy link to clipboard

Copied

@Kukurykus 

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')

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 01, 2022 Jan 01, 2022

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 01, 2022 Jan 01, 2022

Copy link to clipboard

Copied

@Kukurykus 

You can try your code on this text

رومـــــــــــــــــــــي
ميكس جبن (بدون خضراوات)
لحمـــــــــــــــــــــــة
فـــــــــــــــــــــــــراخ
سجــــــــــــــــــــــق
ســـوســــــيــس
بسطــــــــرمـــــة
تـونــــــــــــــــــــــــه
ميكس مدخنات
(سلامى - سموك ترك - بيف مدخن)
ريحانة ( لحمة – سوسيس – بسطرمة )

Also try the modification I made

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines