![]() |
Java to pascal/delphi
:arrow: 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:
>>>>>>>>>> And now my (poor) result in rewriting it, many og the for loops and stuff I DIDNT manedge to translate, but here goes:
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; }
Delphi-Quellcode:
>>> So How am I dooing so far?.. Any corrections, comments or hints?
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; Thanks in advance! [b]Regars PasTra |
Re: HELP: JAVA TO PASCAL/DELPHI
First, try to use the BBCode of the Board. Use the [delphi]-Tag oder the [code]-Tag!
|
Re: HELP: JAVA TO PASCAL/DELPHI
Zitat:
Sorry I did not realize that. I have changed it now.. Any advices ideas to the snippers? |
Re: HELP: JAVA TO PASCAL/DELPHI
When you wait about ten minutes then i have a solution.
What makes exactly this code? Because i doesn't know how to program with Java ;)
Code:
return decodeString(new QStringBuffer(), s).toString();
|
Re: HELP: JAVA TO PASCAL/DELPHI
Zitat:
The way I see it Decodestring is called like like this: var s:string begin s:= DecodeString('Hello'); end; |
Re: HELP: JAVA TO PASCAL/DELPHI
Zitat:
|
Re: HELP: JAVA TO PASCAL/DELPHI
LOL 'what makes this code' i think he 'makes' nothing. he is doing a lot ;)
My Java isn't good enough to translate, but here some tips for pascal-language: to compare to variables, you use '=', e.g.
Delphi-Quellcode:
to assign a variable you use ':=', e.g
if s1=s2 then whatever;
Delphi-Quellcode:
Furthermore there is no
s1:=s2;
Code:
in delphi/pascal, to increase the value of an integer-var by 1, use
l++
Delphi-Quellcode:
or
i:=i+1;
Delphi-Quellcode:
so far
inc(i);
inh3r1ted |
Re: HELP: JAVA TO PASCAL/DELPHI
Try this code - there is no guaranty that it's right :thumb:
Delphi-Quellcode:
// Edit
function decodeStringF2(QStringBuffer : TStringList; s: String): TStringList;
var i, k, j, l : Integer; c : Char; Buffer : TStringList; begin Buffer := QStringBuffer; if(s <> '') then begin i := length(s); // i had to replace the for because i can't change an counter in a for j := 1; // Index in a String is different - in Delphi it starts with 1 while j < i do begin c := s[j]; if c = '&' then begin if (i < j+5) then break; k := 0; for l := 0 to 3 do begin inc(j); k := k*16; k := k + StrToInt(s[j]) - 65; // Here you habe to be careful! The character here must be a number! end; end else begin Buffer.Append(c); end; inc(j); end; end; Result := Buffer; end; function decodeStringF1(s: String): String; var Buffer : TStringList; begin Buffer := TStringList.Create; Buffer := decodeStringF2(Buffer, s); Result := Buffer.Text; end; Deleted some test-code! |
Re: HELP: JAVA TO PASCAL/DELPHI
Hi!
... and Welcome in DP! I can't help you with your problem but I have a little request to you: Could you please change the title of this topic? (simply edit your first post) There a lot of people who are searching for help and so it's not necessary to say "help"! Furthermore the title is easier to read if it's not UPPERCASE! Thank you! Ciao Frederic |
Re: HELP: JAVA TO PASCAL/DELPHI
Zitat:
I have changed it now.. |
Alle Zeitangaben in WEZ +1. Es ist jetzt 19:28 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz