Autor Beitrag
vit30
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 38



BeitragVerfasst: Do 04.03.10 17:00 
Hallo!
Gibt es für string -Variable so ähnliche Methode wie Array.Reverse?
Eine string- Variable soll umgekehrt angezeigt werden.
Z.B. string x = "ABCD", soll in x = "DCBA" umgewandelt werden.
danielf
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1012
Erhaltene Danke: 24

Windows XP
C#, Visual Studio
BeitragVerfasst: Do 04.03.10 17:06 
Hallo,

nicht das ich wüsste. Aber diese Frage hättest du dir sicher mit 3 Minuten google selbst herausfinden können. Ein bisschen mehr Engagement ist sicherlich angebracht. Auch ein blick ins MSDN hilft da problemlos.

Sehr schwach :/

Gruß Daniel
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Do 04.03.10 17:11 
System.Linq bietet eine Reverse-Methode, die auch auf String anwendbar ist.

Moderiert von user profile iconChristian S.: C#-Tags hinzugefügt

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
JüTho
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2021
Erhaltene Danke: 6

Win XP Prof
C# 2.0 (#D für NET 2.0, dazu Firebird); früher Delphi 5 und Delphi 2005 Pro
BeitragVerfasst: Do 04.03.10 17:14 
Und mit "einfachen" Mitteln kann man es selbst basteln, wenn man daran denkt, was ein String mit einem Array zu tun hat. Jürgen
vit30 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 38



BeitragVerfasst: Do 04.03.10 17:18 
user profile iconJüTho hat folgendes geschrieben Zum zitierten Posting springen:
Und mit "einfachen" Mitteln kann man es selbst basteln, wenn man daran denkt, was ein String mit einem Array zu tun hat. Jürgen

Habe ich auch schon gemacht :)
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
for (int i = 0; i < Ergebnis.Length; i++)
            {
                Result = Result + Ergebnis[Ergebnis.Length-i-1];
                
            }
textBox3.Text = Result.ToString();

So sieht es bei mir aus.
Ich wollte nur wissen, ob es noch einfacher geht.
JüTho
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2021
Erhaltene Danke: 6

Win XP Prof
C# 2.0 (#D für NET 2.0, dazu Firebird); früher Delphi 5 und Delphi 2005 Pro
BeitragVerfasst: Do 04.03.10 18:57 
Was ist denn Result für ein Typ? Vermutlich ein String. Was soll dann Result.ToString noch machen?

Wenn deine for-Schleife rückwärts gehen würde, wäre dein Index-Zugriff einfacher.

Daniel hat möglicherweise an etwas Ähnliches gedacht. Meine Idee ging in folgende Richtung:
ausblenden C#-Quelltext
1:
2:
3:
4:
string source = "ABCD";
char[] temp = source.ToCharArray();
Array.Reverse(temp);
string dest = new string(temp);

Jürgen
danielf
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1012
Erhaltene Danke: 24

Windows XP
C#, Visual Studio
BeitragVerfasst: Do 04.03.10 19:17 
Ich meinte eher, dass er bei google zik Varianten findet.

Und wenn man noch weiter google findet man auch einen guten Performance-Vergleich.

Und welche man dann nimmt ist jawohl klar, siehe JüTho ;)
vit30 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 38



BeitragVerfasst: Fr 05.03.10 15:25 
Ich wollte kein Array benutzen...
Danke für interessantes Link,danielf.