Hi, I'm just beginning julia, and have written nearly 100 lines of code! 
Let the stupid question begin:

I thought I'd try to implement the equivalent of Perl's tr/// function (or 
sed's y///) to operate on ASCIIStrings, and I thought an efficient way to 
code it would be to create a look up table, a 256 element array of UInt8 
containing replacement values for each ASCII character, and iterate through 
the string.  It all works fine when I have UInt8[], and I can construct 
them using b"" literal strings:

    # Perl: "hello" =~ tr/ho/bs/
    str = b"hello"
    src = b"ho"
    rpl = b"bs"
    lut = collect(0x00:0xff)
    for i = 1:length(src)
        lut[ src[i] + 1 ] = rpl[i]
    end
    @show str;
    for (i,c) in enumerate(str)
        str[i] = lut[c + 1]
    end
    @show str;

but I can't work out how to convert from an ASCIIString (which doesn't 
allow indexing with UInt8) to Array{UInt8,1} (which doesn't allow indexing 
with Char) and visa versa.

Reply via email to