Autor Beitrag
Luzifer
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 98

WinXP Pro/ Vista
D5 Enterprise/D7 Enterprise/D2005 Architect
BeitragVerfasst: Di 11.08.09 15:31 
Hi Leute

ich brauch mal nen kleinen Gedankenanstoß. Der Plan: In einem String soll jeder 2. Buchstabe zu einem Großbuchstaben, jeder 2. dazwischen soll klein werden. Soweit so gut:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
function UpperandLower(Text:string):string;
var i : integer;
begin
  for i:=1 to length(text) do if i mod 2 = 0 then text[i]:=uppercase(text[i]) else text[i]:=lowercase(text[i]);
  result:=text;
end;


Sieht schön aus, das Problem: Es funktionniert nicht XD der Compiler sagt mir Char und String seien Inkompatible Typen. Ich hab schon verschiedene Möglichkeiten mit Char() probiert, aber ich komm nicht wirklich drauf was mein Compiler meint.^^

thx for help
spawn89
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 82
Erhaltene Danke: 7

Linux
CodeTyphon
BeitragVerfasst: Di 11.08.09 15:37 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
function UpperandLower(Text:string):string;
var
  i: Integer;
begin
  for i:=1 to length(text) do
    if i mod 2 = 0 then
      result := result + UpCase(text[i])
    else
      result := result + LowerCase(text[i])[1];
end;

Man, freu ich mich auf den D2010 CodeFormatter. :)
Luzifer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 98

WinXP Pro/ Vista
D5 Enterprise/D7 Enterprise/D2005 Architect
BeitragVerfasst: Di 11.08.09 15:48 
is das [1] am ende von Zeile 9 Absicht? Wenn ja, welche Bedeutung hat das?
ich habs einfach mal weggelassen, funktioniert so vielen dank!
spawn89
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 82
Erhaltene Danke: 7

Linux
CodeTyphon
BeitragVerfasst: Di 11.08.09 15:51 
LowerCase gibt einen String zurück, und da in einen Char kein ganzer String reinpasst, muss halt leider nur das erste Zeichen genommen werden.
Edit: Ja, bei meiner Version könnte man es sogar weglassen. XD
Luzifer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 98

WinXP Pro/ Vista
D5 Enterprise/D7 Enterprise/D2005 Architect
BeitragVerfasst: Di 11.08.09 15:53 
ah ja natürlich, dass ist der Index aus dem Stringarray....^^