Skip to main content
dublove
Legend
June 25, 2025
Answered

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

  • June 25, 2025
  • 2 replies
  • 561 views

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.

Correct answer rob day

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









2 replies

Community Expert
June 26, 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

-Manan
dublove
dubloveAuthor
Legend
June 26, 2025

Hi Manan Joshi

This is it, thank you very much.

rob day
Community Expert
Community Expert
June 25, 2025

You can do this:

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

alert(valueA1)

 

 

 

dublove
dubloveAuthor
Legend
June 26, 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.

rob day
Community Expert
rob dayCommunity ExpertCorrect answer
Community Expert
June 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