Solved

Removing a character from a string

Posted on 2000-05-09
3
211 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 50 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

710 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