Im trying to write a program that strips out bad char for SQL insert
Things liike ( ' " , ) -
I have tried TStrings but you can not access an individual char ( that I can find) to change. I have tried move but get an access violation. Can you guys assist in a better idea? Right now, I just have it dropping the bad character (which is typically a formatting char i think)
Below is where I am at, but it produces an access violation:
function StripBadSQLChar(sStringGiven: string): string;
var
iCnt: integer;
sReturnString: string;
boolBadChar: boolean;
begin
try
iCnt := 0;
boolBadChar := False;
sReturnString := '';
while (iCnt < length(sStringGiven)) do
begin
case sStringGiven[iCnt] of
#34: begin
boolBadChar := True;
Write('Found quote');
end;
#39: begin
boolBadChar := True;
end;
#92: begin
boolBadChar := True;
end
else
begin
if (boolBadChar = False) then
begin
move(sStringGiven[iCnt], sReturnString[iCnt], 1);
//AppendStr(sReturnString[iCnt], sStringGiven[iCnt]);
//sReturnString[iCnt] := sStringGiven[iCnt];
end;
end;
end;
Inc(iCnt);
end;
finally
Result := sReturnString;
end;
end;