replace all values of a variable by half
-
is there any way to find and replace all values of a variable with the original value divided by two?
-
@Cynic ,
Not natively: the search-and-replace engine doesn’t handle math.
However, if you install the PythonScript plugin and look at the documentation, there’s an example of a search-and-replace using PythonScript that adds 1 to the numbers; you would just have to change that example to divide by 2 instead.
def add_1(m): return 'Y' + str(int(m.group(1)) + 1) # replace X followed by numbers by an incremented number # e.g. X56 X39 X999 # becomes # Y57 Y40 Y1000 editor.rereplace('X([0-9]+)', add_1);becomes
def div_2(m): return 'Y' + str(int(m.group(1)) / 2) # replace X followed by numbers halved # e.g. X56 X24 X99 # becomes # Y28 Y12 Y49 editor.rereplace('X([0-9]+)', div_2); -
thanks a ton!
-
A Alan Kilborn referenced this topic on
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login