Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Removing a character from a string

Posted on 2000-05-09
3
Medium Priority
?
216 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 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

Independent Software Vendors: 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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

722 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