Split() After Specific Number of Words/Characters?

Participant ,
Aug 10, 2022 Aug 10, 2022

Copy link to clipboard

Copied

Greetings all,

 

Got another one that's probably simpler than I'm making it. This is what I'm trying to do:

 

I have a slider named "Camera Input Talent 1 Scale Adjust." Ideally, I'd like to be able to pull two strings from this:

string1 = "Camera Input Talent 1"

string2 = "Scale Adjust"

 

I like the split() function because it splits a string into an array, but all the references I've been able to find indicate that split() will only work with a delimiter that's a character. Is there a way to either get split() to work with a number of characters or a number of words? Or some other way to do what I'm describing?

TOPICS
Expressions , How to

Views

43

Likes

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

Community Expert , Aug 10, 2022 Aug 10, 2022

There might be a simpler way, but I think this will work:

 

str = "Camera Input Talent 1 Scale Adjust.";
numWords = 4;

arr = str.split(" ");
arr1 = arr.slice(0,numWords);
arr2 = arr.slice(numWords);
arr1.join(" ") + "\r" + arr2.join(" ");

 

Likes

Translate

Translate
Community Expert ,
Aug 10, 2022 Aug 10, 2022

Copy link to clipboard

Copied

There might be a simpler way, but I think this will work:

 

str = "Camera Input Talent 1 Scale Adjust.";
numWords = 4;

arr = str.split(" ");
arr1 = arr.slice(0,numWords);
arr2 = arr.slice(numWords);
arr1.join(" ") + "\r" + arr2.join(" ");

 

Likes

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
Participant ,
Aug 10, 2022 Aug 10, 2022

Copy link to clipboard

Copied

LATEST

Dan does it again! As always you know I appreciate it!

Likes

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

Make your promotional social content with Adobe Express.

Get started quickly with free templates: