문제

I have a problem with removing the questionmarks. I don't want them in my SQL-Database. But my code isn't working, and I don't know where the problems are.

function RemoveQMark(sWork: String): String;
begin
  Delete(sWork, 2, 4);
  Delete(sWork, Length, 2);
  Result := sWork;
end;

I want to remove the ? at the first and last position.

도움이 되었습니까?

해결책

There is no need to use Delete on the passed in string. Simply use the Delphi Copy function to copy all but the first and last characters directly to the result:

function RemoveQMark(const sWork: String): String;
begin
  Result := Copy(sWork, 2, Length(sWork) - 2);
end;

Using const on string arguments allows the compiler to generate more efficient code. (Without const, the strings reference count is incremented at the start of the function and decremented at the end (within a try...finally block)).

다른 팁

function RemoveQMark(sWork: String): String;
begin
  Delete(sWork, 1, 1);
  Delete(sWork, Length(sWork), 1);
  Result := sWork;
end;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top