[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Function to Replace a value in a String

Posted on 2001-06-20
5
Medium Priority
?
150 Views
Last Modified: 2010-04-06
Hi,

I'd like to know if there is a function which will replace
a value by another in a string.

I have a string which containts ' . I need to double the '
So I'd like to replace ' by '' .

Example: 'You'll find'   must be 'You''ll find'


Thank you !

Mary
0
Comment
Question by:msl22
5 Comments
 
LVL 3

Accepted Solution

by:
nnbbb09 earned 80 total points
ID: 6212010

You can use StringReplace

eg : result:=StringReplace('Some Text','Text','Message',[rfReplaceAll])

This will return 'Some Message' as the result.

There is also a function called QuotedStr which is used specifically for replace single quotes ' with double quotes ''.

regards

Jo
0
 
LVL 1

Expert Comment

by:Dennis9
ID: 6212027
Hi.
nnbbb09 is right, but u could also use this:

procedure TForm1.Button1Click(Sender: TObject);
var
s: String;
FoundPos, i: Integer;
begin
s := Edit1.Text;
for i := 1 to Length(s) do
begin
FoundPos := Pos(' ', s);//The stuff to search for
if FoundPos <> 0 then
begin
Delete(s, FoundPos, 1);
Insert('+', s, FoundPos);//The item to replace with
end;
end;
Edit1.Text := s;
end;


//Another exampel of StringReplace:
edit1.text := StringReplace(Edit1.Text, ' ', '+', [rfReplaceAll]);


Hope it helped
Dennis
0
 
LVL 3

Expert Comment

by:VSF
ID: 6212152
This should do it!
Just another way....

VSF
www.enge.cjb.net
www.victory.hpg.com.br

function ReplaceText(const S,ReplacePiece,ReplaceWith: String):String;

Var Position: Integer;
    TempStr: String;
begin
  Position := Pos(ReplacePiece,S);
  if Position > 0 then Begin
    TempStr := S;
    Delete(TempStr,1,Position-1+Length(ReplacePiece));
    Result :=
Copy(S,1,Position-1)+ReplaceWith+ReplaceText(TempStr,ReplacePiece,ReplaceWith)

  End else Result := S;
end;
0
 
LVL 20

Expert Comment

by:Madshi
ID: 6213122
If you need something as fast as possible, you should look here for a solution that will outperform all other suggestions, that were made yet...   :-)

http://help.madshi.net/Data/StringManipulate.htm#ReplaceStr

Regards, Madshi.
0
 

Author Comment

by:msl22
ID: 6214119
Thank you for all of you !!!
I really appreciate your comment !

Have a nice day.

Mary
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

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…
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…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

829 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