?
Solved

Function to Replace a value in a String

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

Introducing Priority Question

Increase expert visibility of your issues by participating in Priority Question, our latest feature for Premium and Team Account holders. Adjust the priority of your question to get emergent issues in front of subject-matter experts for help when you need it most.

Question has a verified solution.

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

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 my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
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
Course of the Month15 days, 8 hours left to enroll

741 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