?
Solved

Replace a character???

Posted on 2003-03-07
8
Medium Priority
?
234 Views
Last Modified: 2013-12-03
is there a function to replace a character rather doing it by searching each character. Example, when someone types D'Amico , I want that everytime theres a ' in a word, it must add another ' so that it will be D''Amico. Anyone know how without doing it manually meaning look for each letter to see if its a '. Thanks
0
Comment
Question by:fb132
[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
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 5

Accepted Solution

by:
Lukasz Lach earned 40 total points
ID: 8089964
s := StringReplace(s, 'old_char', 'new_char', [rfReplaceAll]);
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 8091570
procedure ReplaceChar(S: string; new_char,old_char: Char);
var
  I:  Integer;
begin
  while (Pos(old_char, S)>0) do
  begin
    I := Pos(old_char, S);
    S[I] := new_char;
  end;
end;
0
 
LVL 34

Expert Comment

by:Slick812
ID: 8092713
hello fb132, I am not understanding what you want to do, but you say  "when someone types D'Amico". . . so I guess this is in a TMemo or Tedit ect?. .  anyway, there is a OnKeyPress event in Text input controls, which let's you monitor the charaters, that go into the control, you can change or add charaters in the KeyPress

procedure TForm1.Memo1KeyPress(Sender: TObject; var Key: Char);
begin
inherited;
if Key = ''' then
 Memo1.SelText := Key;

end;
0
Technology Partners: 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!

 
LVL 34

Expert Comment

by:Slick812
ID: 8092719
should be
if Key = '''' then
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 8092777
i forgot it must to be function:

function ReplaceChar(S: string; new_char,old_char: Char): string;
var
 I:  Integer;
begin
  try
    while (Pos(old_char, S)>0) do
    begin
      I := Pos(old_char, S);
      S[I] := new_char;
    end;
  finally
    Result := S;
  end;
end;
0
 
LVL 5

Expert Comment

by:Lukasz Lach
ID: 8093359
s := StringReplace(s, '''', '''''', [rfReplaceAll]);

That changes ' to '', what is the problem? ;-)
0
 
LVL 1

Expert Comment

by:Wax0r
ID: 8093531
Also Slick, my guess is it's to make sure SQL server or an Access database or god knows what else doesn't bitch about storing things when there's only one ' in there.

anAKIN answered it though
0
 
LVL 5

Expert Comment

by:Lukasz Lach
ID: 8093791
why c? isn't that the best way to replace chars so what you expected? ;/
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

777 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