Autor Beitrag
raiha
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 152



BeitragVerfasst: Di 23.08.05 12:41 
Hi,

ich muss einen String auf Apostrophe durchsuchen und wenn eines gefunden wurde an der gleiche Stelle noch eins einfügen das es keine Konflikt mit der DB gibt.

das habe ich schon:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
        for SearchIndex := 1 to length(ApostropStr) do
         begin
                if ApostropStr[SearchIndex] = 
        ...


Wie muss ich jetzt weitermachen?

Danke Rainer

Moderiert von user profile iconKlabautermann: Code- durch Delphi-Tags ersetzt.
uall@ogc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1826
Erhaltene Danke: 11

Win 2000 & VMware
Delphi 3 Prof, Delphi 7 Prof
BeitragVerfasst: Di 23.08.05 12:45 
= ''''

_________________
wer andern eine grube gräbt hat ein grubengrabgerät
- oder einfach zu viel zeit
raiha Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 152



BeitragVerfasst: Di 23.08.05 12:49 
ja- es geht auch mit #39

aber wie ersetze ich jetzt das Apostroph duch 2 Apostrophe?
WeBsPaCe
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Di 23.08.05 12:56 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
function InsertAph(AString: String; APos: Integer): String;
var
  i: Integer;
begin
  Result := '';
  for i := 1 to APos do
    Result := Result + AString[i];
  Result := Result + Chr(39);
  for i := APos+1 to Length(AString) do
    Result := Result + AString[i];
end;


;)
I.MacLeod
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 109



BeitragVerfasst: Di 23.08.05 13:03 
Ich würde entweder Suche in: Delphi-Forum, Delphi-Library STRINGREPLACE oder irgendwas selbstgebautes vorschlagen:

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
function Foobar(s: string): string;
var
  p, p2: pchar;
  i: integer;
begin
  p := Pointer(s);
  i := 0;
  while p^ <> #0 do
  begin
    if p^ = '''' then
      inc(i);
    inc(p);
  end;
  if i = 0 then
  begin
    Result := s;
    exit;
  end;
  SetLength(Result, Length(s)+i);
  p := Pointer(s);
  p2 := Pointer(Result);
  while p^ <> #0 do
  begin
    p2^ := p^;
    if p^ = '''' then
    begin
      inc(p2);
      p2^ := '''';
    end;
    inc(p2);
    inc(p);
  end;
end;


:mrgreen:

_________________
{$APPTYPE CONSOLE}uses SysUtils;const a='{$APPTYPE CONSOLE}uses SysUtils;const a=%s;begin write(Format(a,[#39+a+#39]))end.';begin write(Format(a,[#39+a+#39]))end.
raiha Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 152



BeitragVerfasst: Di 23.08.05 13:07 
Was haltet ihr von dieser Lösung? Habe es jetzt so gemacht :-)

ausblenden Delphi-Quelltext
1:
StringReplace(mystring, #39, '''''',[rfReplaceAll]);					

Danke - Tschüss Rainer
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Di 23.08.05 13:08 
Machts doch einem Anfänger nicht so schwer...
ausblenden Delphi-Quelltext
1:
MyString := StringReplace(MyString, '''', '''''', [rfReplaceAll]);					


EDIT: Auch schön, wenn der Fragesteller vor dem Fragebeantworter die Antwort schon hat :)

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
WeBsPaCe
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Di 23.08.05 13:25 
user profile iconraiha hat folgendes geschrieben:
Was haltet ihr von dieser Lösung? Habe es jetzt so gemacht :-)

Joa. So kannstes auch machen. :lol:

user profile iconGTA-Place hat folgendes geschrieben:
Machts doch einem Anfänger nicht so schwer...

Meinst du mich? :mrgreen:
Amiga-Fan
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 534



BeitragVerfasst: Di 23.08.05 13:31 
warum einfach, wenn es auch kompliziert geht? Wieso habt Ihr ihm keine rekursive Funktion angeboten? :D

Zitat:
ich muss einen String auf Apostrophe durchsuchen und wenn eines gefunden wurde an der gleiche Stelle noch eins einfügen das es keine Konflikt mit der DB gibt.


benutzt quotedstr oder parameter.

_________________
- Leg dich nie mit einem Berufsprogrammierer an
- Wahre Profis akzeptieren keine einfachen Lösungen