BMS, Movie, Illustrations, Programming

text.sourceText には replaceAll が無いが string.prototype.replaceAll はある【After Effects エクスプレッション】

thisComp.layer("_expression_source_text")
  .text
  .sourceText
  .replaceAll("\n", "");

これはダメだけど、

 thisComp.layer("_expression_source_text")
   .text
   .sourceText
+  .toString()
   .replaceAll("\n", "");

これは OK らしい。(AE 2024 で動作確認。)sourceText は string ではないので特に変なことではないけれど、初心者では気付きづらいかもしれない。

ExtendScript でも似たような感じっぽかったですが、 getOwnPropertyNames() が使えなかったので細かい差異までは確認していません。

ちなみに上記のコードの場合は別に .split("...").join("...") でも良くて、この場合は .toString() が不要で、文字数が少なくて済む。

string にしかない他のメソッド

  • anchor
  • at
  • big
  • blink
  • bold
  • codePointAt
  • matchAll
  • normalize
  • padEnd
  • padStart
  • replaceAll
  • trimEnd
  • trimLeft
  • trimRight
  • trimStart
  • fixed (*deprecated)
  • fontcolor (*deprecated)
  • fontsize (*deprecated)
  • italics (*deprecated)
  • link (*deprecated)
  • small (*deprecated)
  • strike (*deprecated)
  • sub (*deprecated)
  • sup (*deprecated)