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()
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.

  • Thank you, but no that doesn't work. The problem seems to be in the replace function from string. – Hamid Jul 21 '16 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. – Charles Stewart Jul 21 '16 at 13:46
  • 0 down vote accept Sorry, No. Where can some one find the documentation for replace method? – Hamid Jul 21 '16 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. – Charles Stewart Jul 22 '16 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()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.