Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #9999
    ldm
    Participant

    I need a help for writing a JavaScript, which place a character (let’s say the [] brackets) around the highlighted text.
    Thank you!

    #10002
    ToadLoadin
    Member

    Hi, I’m not a JavaScript geek, but I guess you could use code like:

    charBefore = "[;
    charAfter = ]";
    strSelectedText = document.selection.Text;

    document.selection.Text = charBefore + strSelectedText + charAfter;
    #10003
    Stefan
    Participant

    Yes i do it the same way:


    #title = "Enclose selection";
    #tooltip = "Enclose an selection with an sign";
    // Select some text and execute this macro to put an sign
    // in front and at the end of the selected text;

    //mySign = "\%"
    mySign = prompt( "Enter sign to enclose selection:", "\%" );

    selText = document.selection.Text;
    outText = mySign + selText + mySign;


    //alert(outText);
    document.selection.Text = outText;

    Should be easy to modify this code
    and replace mySign with LeadingSign and TrailingSign :-)

    #10004
    ldm
    Participant

    ToadLoadin & Stefan! Thanks a lot!
    But now I need one more tip please :-)
    Does JavaScript supports Regular Expressions?
    Let’s say I need to replace a text, which matches the pattern ^(;[ ]*[ ])(.*) with this one: 1[2]
    How would I do so?
    Thank you!

    #10008
    Stefan
    Participant

    EmEditor Help – EmEditor Macro Reference – Tutorial > Using Regular Expressions

    EmEditor Help – How to – Search > Regular Expression Syntax

    #10009
    ldm
    Participant

    Stefan, the issue is not with the RegEx syntax, but how use the RegEx expressions inside of the Java Scripts (please see my previous post).
    How should I let to Java know that I wrote a regular expression and not just a string?
    Thank you!

    #10010
    ldm
    Participant

    Stefan,
    I’ve got it!
    Thanks!

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.