Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 30th December 2011, 22:38   #1  |  Link
vampiredom
Registered User
 
Join Date: Aug 2008
Posts: 233
ord() | Return the ASCII value of a character

Here is a useful function I wrote for returning to ASCII value of a character, like the reverse of chr()

Note that AviSynth seems to ignore CHR(0) in strings ... A blank string will always return 0.

Code:
# requires Gscript.dll
global __ord_ASCII__ = ""

function ord(string c) {
        c = LeftStr(c,1)
        
        Gscript("""
        if (__ord_ASCII__ == "") {
                for (i=1, 255, 1) {
                        global __ord_ASCII__ = __ord_ASCII__ + chr(i)
                }
        }
        """)
        
        return (c == "") ? 0 : FindStr(__ord_ASCII__, c)
}

Last edited by vampiredom; 30th December 2011 at 23:19.
vampiredom is offline   Reply With Quote
Old 30th December 2011, 23:04   #2  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,439
Quote:
Originally Posted by vampiredom View Post
Code:
global __ord_ASCII__ = ""
...
        if (__ord_ASCII__ == "") {
                for (i=1, 255, 1) {
                        __ord_ASCII__ = __ord_ASCII__ + chr(i)
                }
        }
This assignment is setting a local variable, so the loop will be redone on each call. Should be:
Code:
                        global __ord_ASCII__ = __ord_ASCII__ + chr(i)
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 30th December 2011, 23:19   #3  |  Link
vampiredom
Registered User
 
Join Date: Aug 2008
Posts: 233
Oops! Fixed. Thanks. [without that, it would kind of defeat the whole reason I wrote the function this way, wouldn't it? ]

Last edited by vampiredom; 31st December 2011 at 03:15.
vampiredom is offline   Reply With Quote
Reply

Tags
ascii, character, chr, gscript, ordinal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:20.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.