Solved

Removing a character from a string

Posted on 2000-05-09
3
209 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 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
proper way to parse text with delphi 7 137
Run video youtube webbrowse 10 65
Delphi...Split view - idea? 1 87
how to make 2 step back? ..\..\ ExtractFilePath (paramstr(0)) 5 46
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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
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…

791 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