uhoang
asked on
Removing a character from a string
Is there a function that will remove a character from a string. I wrote a little loop to do it for me but the problem is that I don't know how to terminate it the way I want it. Take a look:
intTemp := pos('''',strTemp2);
if (intTemp > 0) then
begin
intTemp := intTemp + 1;
While (strTemp2[intTemp] <> #0) do
begin
strTemp2[intTemp - 1] := strTemp2[intTemp];
intTemp := intTemp + 1;
end;
strTemp2[intTemp - 1] := #10;
end;
Basically what the code above does is remove any single quotes (') from strTemp2. So if strTemp2 is 'hershey's' then after the routine it should be 'hersheys'.
The problem I have with this is that the results ends up being 'hersheys'#0. I don't want that null-terminating character to be there, but I don't know what else I could do.
intTemp := pos('''',strTemp2);
if (intTemp > 0) then
begin
intTemp := intTemp + 1;
While (strTemp2[intTemp] <> #0) do
begin
strTemp2[intTemp - 1] := strTemp2[intTemp];
intTemp := intTemp + 1;
end;
strTemp2[intTemp - 1] := #10;
end;
Basically what the code above does is remove any single quotes (') from strTemp2. So if strTemp2 is 'hershey's' then after the routine it should be 'hersheys'.
The problem I have with this is that the results ends up being 'hersheys'#0. I don't want that null-terminating character to be there, but I don't know what else I could do.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the FAST response!
take a look to this procedure
Removes a substring from a s string.
Unit
System
Category
string handling routines
procedure Delete(var S: string; Index, Count:Integer);
Description
Delete removes a substring of Count characters from string S starting with S[Index]. S is a string-type variable. Index and Count are integer-type expressions.
If Index is larger than the length of S, no characters are deleted. If Count specifies more characters than remain starting at the S[Index], Delete removes the rest of the string.
meikl