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

How to achieve this with scripting: processing and mixing some data, want to make it complex.

Guide ,
Jun 25, 2025 Jun 25, 2025

For example:

My initial data for:  var valueA1=ABCDEDR;

 

Now I perform a transformation on it:
Repeat for the first digit, and the last digit. I get the following:
var valueA2=AABCDEDRR;

 

Next, mix it again.

At the end, merge in a specific character, e.g. var ValueB=yesOKNO@22@

 

Eventually get:
var ValueA3=AABCDEDRRyesOKNO@22@;

 

Thank you very much.

TOPICS
Scripting
275
Translate
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

Community Expert , Jun 26, 2025 Jun 26, 2025

Here are examples of the relevant string methods

 

var str = 'Hello World';

$.writeln(str.charCodeAt(0))
//Returns unicode for "H" 72

$.writeln(str.concat(' Hello', " There"))
//returns: Hello World Hello There

$.writeln(str.indexOf('o'))
// Returns: 4 (the first o index)

$.writeln(str.lastIndexOf('o'))
// Returns: 7 (the last o index)

$.writeln(str.match("\\w+"))
// Returns: regular expression search "Hello"

$.writeln(str.replace("World", "Planet"))
// Returns: Hello Planet

$.writeln(str
...
Translate
Community Expert ,
Jun 25, 2025 Jun 25, 2025

You can do this:

var valueA1 = "ABCDEDR"
valueA1 = "A"+valueA1+"R"
valueA1 = valueA1 + "yesOKNO@22@"

alert(valueA1)

 

 

Screen Shot 38.png

 

Translate
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
Guide ,
Jun 25, 2025 Jun 25, 2025

Hi rob day

How to repeat a character, such as the 1st, 3rd, and last.
They are indeterminate, not necessarily A or R.
determines just the position.

Translate
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
Community Expert ,
Jun 26, 2025 Jun 26, 2025

Here are examples of the relevant string methods

 

var str = 'Hello World';

$.writeln(str.charCodeAt(0))
//Returns unicode for "H" 72

$.writeln(str.concat(' Hello', " There"))
//returns: Hello World Hello There

$.writeln(str.indexOf('o'))
// Returns: 4 (the first o index)

$.writeln(str.lastIndexOf('o'))
// Returns: 7 (the last o index)

$.writeln(str.match("\\w+"))
// Returns: regular expression search "Hello"

$.writeln(str.replace("World", "Planet"))
// Returns: Hello Planet

$.writeln(str.slice(0, 7))
// Returns: Hello W

$.writeln(str.split(" "));
// Returns an array of words: [Hello,World] array

$.writeln(str.substring(0, str.length-6))
// Returns: "Hello"

$.writeln(str.substring(4))
// Returns: "o World"

$.writeln(str.substring(6, 11));
// Returns: "World"

$.writeln(str.substring(str.length-1));
// Returns: "d"

$.writeln(str.toLocaleLowerCase());
// Returns: "hello world"

$.writeln(str.toLowerCase());
// Returns: "hello world"

$.writeln(str.toLocaleUpperCase());
// Returns: "hello world"

$.writeln(str.toUpperCase());
// Returns: "hello world"


$.writeln(str.indexOf('Y'))
// Returns: -1 because Y is not in the string









Translate
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
Guide ,
Jun 26, 2025 Jun 26, 2025

Hi rob day.

This is great.
I'm testing them one by one.

This is so comprehensive. I've been stuck or learning that there are no simple examples in the hand rules.

 

$.writeln

But I still want to ask what is $.writeln?
Is it something like alert();
but $.writeln doesn't output that either.

 

It seems that it is also not possible to directly repeat the 1st character of the command.

Thank you very much.

 

Translate
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
Community Expert ,
Jun 26, 2025 Jun 26, 2025

$.writeln prints the message in the console of the editor from which you execute the script i.e. VSCode or ESTK. This is used by script developers, it won't display anything if you execute the script via scripts panel.

-Manan

Translate
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
Community Expert ,
Jun 26, 2025 Jun 26, 2025

In VSCode you get this

 

Screen Shot 39.png

Translate
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
Guide ,
Jun 26, 2025 Jun 26, 2025

Hi rob day,  Manan Joshi

Learned, thank you very much.

I'm all about testing with alert in ID, and I feel like ID comes pretty fast and doesn't need to be configured.
Mostly I don't have time to configure VS right now.

Translate
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
Community Expert ,
Jun 26, 2025 Jun 26, 2025
LATEST

Without a debugger app you would have to use alert().

 

You also can't get much in the way of error feedback or code help from a plain text editor.

Translate
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
Community Expert ,
Jun 25, 2025 Jun 25, 2025

What you described is just string manipulation and currently it is just appending string at the start or end. If your actual need would require operations like adding/removing/querying part of string from a defined location etc you would need more that append functionality. For all the string functions available to you, check out the following link

InDesign ExtendScript API Adobe InDesign 2025 (20.0.0.95) Object Model - String

-Manan

Translate
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
Guide ,
Jun 25, 2025 Jun 25, 2025

Hi Manan Joshi

This is it, thank you very much.

Translate
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