Spencer
Spencer

Reputation: 457

Check String equality of Slide textbox

I'm using SlidesApp.getActivePresentation.getSlides[0].getPageElements()[0].asShape().getText().asString() to get the text of the title of the slide. However, when I try to check the text in an equality statement like SlidesApp.getActivePresentation.getSlides[0].getPageElements()[0].asShape().getText().asString() == "XYZ Company" it returns false. What do I need to do to accurately check that a given Slide page element textbox contains certain text?

Upvotes: 0

Views: 558

Answers (2)

Spencer
Spencer

Reputation: 457

It seems the type of textbox was adding a trailing line break, so s.getPageElements()[0].asShape().getText().asString().trim() == "XYZ Company" evaluates true

Upvotes: 0

SputnikDrunk2
SputnikDrunk2

Reputation: 4048

Alternative Solution:

You can also try using the JavaScript String includes() method as it will only check if a string includes the word you're looking for & it will disregard any new lines or spaces on the string. See this sample below:

function test() {
  var slide = SlidesApp.getActivePresentation().getSlides()[0].getPageElements()[0].asShape().getText().asString();
  Logger.log(slide.includes("XYZ Company"));
}

Sample:

enter image description here

Upvotes: 1

Related Questions