Solved

Removing a character from a string

Posted on 2000-05-09
3
206 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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks for the FAST response!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now