Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Most efficient way of injecting line breaks

  • Most efficient way of injecting line breaks

  • Edward Clayton

    September 23, 2022 at 1:25 pm

    As part of a larger expression, I need to inject line breaks after each character in a string. I have something that works (hacked together from another post here), but was wondering if there is a more efficient method, since I’ll need to be doing this to multiple strings at once.

    idx = 0;

    outStr = "";

    while (idx < value.length){

    if (idx > 0) outStr += "\r";

    outStr += value.substr(idx,1);

    idx += 1;

    }

    outStr

  • Dan Ebberts

    September 23, 2022 at 2:20 pm

    Like this maybe:

    value.replace(/.{1}/g, '$&\r')
  • Edward Clayton

    September 23, 2022 at 2:24 pm

    Brilliant! Thank you, Dan 🙏

  • Edward Clayton

    September 23, 2022 at 2:50 pm

    How could I replace the hard-coded line break with a variable?

    v = "\r";

    And is there a good reference/directory for this type of syntax (i.e. “‘$&\r'”)?

  • Dan Ebberts

    September 23, 2022 at 4:45 pm

    Like this:

    v = "\r";
    value.replace(/.{1}/g, '$&' + v)

    Any good JavaScript + Regular Expression reference should do.

  • Edward Clayton

    September 23, 2022 at 4:56 pm

    I thought I tried that, but I must have had a typo somewhere…works perfect! Thanks again.

Viewing 1 - 6 of 6 posts

Log in to reply.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy