Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Removing a character from a string

Posted on 2000-05-09
3
Medium Priority
?
219 Views
Last Modified: 2010-04-04
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.
0
Comment
Question by:uhoang
  • 2
3 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2792818
hi uhoang,

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
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 200 total points
ID: 2792863
hi again,

a little sample

Function StripChar(AString : String; AChar : Char) : String;
var
  P : Integer;
  S : String;
begin
  S := AString;
  P := pos(AChar,S);
  While P > 0 do
  begin
    Delete(S,P,1);
    P := pos(AChar,S);
  end;
  Result := s;
end;

//sample to call
procedure TForm1.Button1Click(Sender: TObject);
var s : string;
begin
  edit1.Text := StripChar(edit1.Text,'.');
end;

meikl
0
 

Author Comment

by:uhoang
ID: 2792964
Thanks for the FAST response!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Loops Section Overview

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question