Copy link to clipboard
Copied
I am trying to search for a certain letter in the last line of a text with always different numbers of lines. I have already managed the search for the letter, I am only missing the possibility to limit the search to the last line. Sometimes it is only one line and sometimes two or even more.
var t = sourceRectAtTime().top;
var h = sourceRectAtTime().height;
var y = t + h;
var txt = text.sourceText;
var find = txt.includes("p");
if(find == true){[value[0], y-5]} else {[value[0], y]}
I tried it with .split("r")[x]; but I can only select a certain line, which doesn't help if I don't know which one is the last.
var t = sourceRectAtTime().top;
var h = sourceRectAtTime().height;
var y = t + h;
var txt = text.sourceText;
var t1 = txt.split("r")[0];
var t2 = txt.split("r")[1];
var t3 = txt.split("r")[2];
var t4 = txt.split("r")[3];
var find = t2.includes("p");
if(find == true){[value[0], y-5]} else {[value[0], y]}
Thanks for helping me!
Something like this maybe:
var t = sourceRectAtTime().top;
var h = sourceRectAtTime().height;
var y = t + h;
var txt = text.sourceText.split("\r");
y -= txt[txt.length-1].indexOf("p") > -1 ? 5 : 0;
[value[0], y]
Copy link to clipboard
Copied
The last line is simply the last entry in the array you create with .split():
mLast=txt.split("\r").length;
From there addressing the last line is simply mLast-1 to adjust for the different counting and that is the only line you need to test. Your syntax seems botched, though. a carriage return is \r, not just r.
Mylenium
Copy link to clipboard
Copied
Thank you very much for your answer. I'm not quite sure how to implement the line in my code, unfortunately. I don't have much experience with expressions yet. Can you give me an example?
Copy link to clipboard
Copied
Something like this maybe:
var t = sourceRectAtTime().top;
var h = sourceRectAtTime().height;
var y = t + h;
var txt = text.sourceText.split("\r");
y -= txt[txt.length-1].indexOf("p") > -1 ? 5 : 0;
[value[0], y]
Copy link to clipboard
Copied
Thank you very much!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now