3

I was wondering how can create a texstudio script for removing the $ $ notation. what is the problem of following code.

%SCRIPT
txt = cursor.selectedText()
txt.replace("$","")
editor.write(txt)
cursor.clearSelection()

2 Answers 2

3

Fixed attempt:

%SCRIPT
var txt = cursor.selectedText()
editor.replaceSelectedText( txt.replace(/[$]/g,"") )
cursor.clearSelection()

The syntax of regular expressions and the replace method are documented on the MDN at their Regular Expressions and String.prototype.replace() pages.

4
  • Thank you, but no that doesn't work. The problem seems to be in the replace function from string.
    – Hamid
    Jul 21, 2016 at 10:16
  • @Hamid I've updated my answer: the replace method only replaces once when invoked with a string as first argument. Hopefully this now works. Jul 21, 2016 at 13:46
  • 0 down vote accept Sorry, No. Where can some one find the documentation for replace method?
    – Hamid
    Jul 21, 2016 at 19:28
  • @Hamid I see you have figured things out. For the sake of other readers I have fixed my answer and provided links to documentation. Jul 22, 2016 at 9:24
1

With the help of Charles Stewart I finnaly got the answer

%SCRIPT
var txt = cursor.selectedText()
var str = txt.replace(/[$]/g,"")
editor.replaceSelectedText(str)
cursor.clearSelection()

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .