[Shapelib] SHPOpen (and SHPCreate) only recognizes the first letter of filename

Tom Kazimiers 2voodoo at gmx.de
Wed Jul 18 07:59:59 PDT 2007


Hello again,

I just want to state that the trick with building a fake-unicode string
works very well, thanks again - if someone needs a code snipped to this
(C#):

private string convertToFakeAscii(string input)
        {
            int count = 0;  
            byte[] byteArray = Encoding.Unicode.GetBytes(input);
            int length = input.Length;
            byte[] newByteArray;

            if (length % 2 == 0)
                newByteArray = new byte[length + 2]; // we need a new
double byte for the \0 at the end
            else
                newByteArray = new byte[length + 1]; // we only need one
byte to fill up the current double byte

            for (int i = 0; i < byteArray.Length; i++) // kick out the
0x00's at every second position :)
                if (i % 2 == 0) {
                    newByteArray[count] = byteArray[i];
                    count++;
                }

            newByteArray[count] = 0;
            if (length % 2 == 0) {
                count++;
                newByteArray[count] = 0;
            }
            return Encoding.Unicode.GetString(newByteArray, 0,
newByteArray.Length);
        }


Bye,
Tom



More information about the Shapelib mailing list