• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Search for a certain letter in the last line of a text with always different numbers of lines

Community Beginner ,
Jul 13, 2023 Jul 13, 2023

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!

TOPICS
Expressions , FAQ , How to

Views

146

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 , Jul 13, 2023 Jul 13, 2023

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]

Votes

Translate

Translate
LEGEND ,
Jul 13, 2023 Jul 13, 2023

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

Votes

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
Community Beginner ,
Jul 13, 2023 Jul 13, 2023

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?

Votes

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
Community Expert ,
Jul 13, 2023 Jul 13, 2023

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]

Votes

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
Community Beginner ,
Jul 13, 2023 Jul 13, 2023

Copy link to clipboard

Copied

LATEST

Thank you very much!

Votes

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