Einzelnen Beitrag anzeigen

pastra

Registriert seit: 23. Jun 2006
21 Beiträge
 
#1

Java to pascal/delphi

  Alt 23. Jun 2006, 22:11
Hi, can anyone help me with this code written i java..

If you have the required knowledge, please help.!



I started translating this JAVA into pascal code:
Delphi-Quellcode:
public static String decodeString(String s)
    {
        return decodeString(new QStringBuffer(), s).toString();
    }


    public static QStringBuffer decodeString(QStringBuffer qstringbuffer, String s)
    {
        if(s == null)
            return qstringbuffer;
        int i = s.length();
        for(int j = 0; j < i; j++)
        {
            char c = s.charAt(j);
            if(c == '&')
            {
                if(i < j + 5)
                    break;
                int k = 0;
                for(int l = 0; l < 4; l++)
                {
                    j++;
                    k *= 16;
                    k += s.charAt(j) - 65;
                }


                qstringbuffer.append((char)k);
            } else
            {
                qstringbuffer.append(c);
            }

        }

        return qstringbuffer;
    }
>>>>>>>>>> And now my (poor) result in rewriting it, many og the for loops and stuff I DIDNT manedge to translate, but here goes:

Delphi-Quellcode:
function decodeString(String s)
begin
result:= decodeString(new QStringBuffer(), s).toString();
end;


    function QStringBuffer decodeString(QStringBuffer qstringbuffer, String s)
    var
    i,k,j,l:integer;
    c:char;
    qstringbuffer: Tstringlist;
    begin
        if(s == null)
        result:= qstringbuffer;
        i = length(s);

        for(j = 0; j < i; j++)
        begin
            c = s[j];
            if c ='&then
            begin
                if(i < j + 5)
                    break;
                k = 0;
                for(l = 0; l < 4; l++)
                begin
                    j:=j+1;
                    k :=k*16;
                    k =k+s[j] - 65;
                end;

                qstringbuffer.append((char)k);
            end else
            begin
                qstringbuffer.append(c);
            end;
        end;

        result:= qstringbuffer;
    end;
>>> So How am I dooing so far?.. Any corrections, comments or hints?


Thanks in advance!

[b]Regars PasTra
  Mit Zitat antworten Zitat