Advertisement
tp7

avisynth string formatting function

tp7
Jan 8th, 2014
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Colorbars(1920, 1080, "YV12")
  2.  
  3. function build_format_function(int arguments_count) {
  4.     args_string = ""
  5.     for(i = 1, arguments_count) {
  6.         args_string = args_string + """, val "p""" + string(i) + """""""
  7.     }
  8.  
  9.     Eval("""
  10.    function format(string fmt""" + args_string + """) {
  11.        for(i = 1, """ + string(arguments_count) + """) {
  12.            try {
  13.                value = string(eval("p" + string(i)))
  14.                fmt = strreplace(fmt, "{"+string(i)+"}", value)
  15.            } catch(ignored) {
  16.      
  17.            }
  18.        }
  19.        return fmt
  20.      
  21.      
  22.        function strreplace(string haystack, string needle, string replace) {
  23.            slen = strlen(needle)
  24.            rlen = strlen(replace)
  25.            olen = strlen(haystack)
  26.            pos = findstr(haystack, needle)
  27.            if (pos == 0) {
  28.                return haystack
  29.            }
  30.            lstr = leftstr(haystack,pos-1)
  31.            rstr = rightstr(haystack,olen-pos-slen+1)
  32.            return lstr + replace + strreplace(rstr, needle, replace)
  33.        }
  34.    }
  35.    """)
  36. }
  37.  
  38. build_format_function(40)
  39.  
  40. Subtitle(format("{1}, this is an {2}: {3}", "Hey look", "int", 5))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement