Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Function to Replace a value in a String

Posted on 2001-06-20
5
Medium Priority
?
149 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
[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
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

Industry Leaders: 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

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…
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

636 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