Skip to main content
dublove
Legend
Jun 25, 2025 5:00 PM UTC
Answered

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

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.

rob day
rob dayCorrect answer
Community Expert
Jun 26, 2025 2:17 PM UTC

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









10 replies

Community Expert
Jun 26, 2025 1:10 AM UTC

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
-Manan
dublove
dubloveAuthor
Legend
Jun 26, 2025 3:35 AM UTC

Hi Manan Joshi

This is it, thank you very much.

Translate
rob day
Community Expert
Community Expert
Jun 25, 2025 10:36 PM UTC

You can do this:

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

alert(valueA1)

 

 

 

Translate
dublove
dubloveAuthor
Legend
Jun 26, 2025 3:37 AM UTC

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
rob day
Community Expert
rob dayCommunity ExpertCorrect answer
Community Expert
Jun 26, 2025 2:17 PM UTC

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