Skip to main content
brandonb96942845
Inspiring
August 10, 2022
Answered

Split() After Specific Number of Words/Characters?

  • August 10, 2022
  • 1 reply
  • 487 views

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?

This topic has been closed for replies.
Correct answer Dan Ebberts

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(" ");

 

1 reply

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
August 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(" ");

 

brandonb96942845
Inspiring
August 10, 2022

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