?
Solved

How to do this?

Posted on 1998-09-10
12
Medium Priority
?
233 Views
Last Modified: 2010-04-06
i got a string...add1~add2~add3~add4
i want to replace ~ with return
what is the command??
If i have a string such as AA3123, i want to convert to 3123..What function should i use..Is there any free componets  available for download. Where can i find free componets widely available?
Anyone?? Thanx...
0
Comment
Question by:dagger
[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
  • 3
  • 2
  • +2
12 Comments
 

Author Comment

by:dagger
ID: 1339211
Edited text of question
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1339212
dagger,

(1) i1:=Pos('~',str);
    while i1<>0 do begin
      Delete(str,i1,1); Insert(#$D#$A,str,i1);
      i1:=Pos('~',str);
    end;
(2) Delete(str,1,2);

Is that what you need?

Regards, Madshi.
0
 
LVL 4

Expert Comment

by:d003303
ID: 1339213
Yo dagger,
your starting point for free components can be
the DSP (Delphi Super Pages)
http://sunsite.icm.edu.pl/delphi/

The Delphi Exchange
http://www.delphiexchange.com/

or Torry's Delphi pages
http://carbohyd.siobc.ras.ru/torry/

Replacing characters in strings is quite easy. Take a look at the functions Insert, Delete, Copy and Pos.

slash/d003303
0
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!

 

Author Comment

by:dagger
ID: 1339214
Thank you guys...
The reason i am asking, is b'cos i find it very difficult to do programming if i were to replace ~ with Return. If i can find a suitable component or maybe a function which enable me to do this i.e
Str1 = address1~address2~address3~address4
NewStr = Replace("~","Return",Str1)
So i get the new formatted address...

but anyway i will check the other functions...Thank you Madshi and d003303. Really appreciate.
0
 
LVL 10

Accepted Solution

by:
Jacco earned 0 total points
ID: 1339215
Here is a function I use:

function StrTran( sSource, sSearch, sReplace: string ): string;
var
  iPosition: integer;
begin
  iPosition := Pos( sSearch, sSource );
  while iPosition > 0 do begin
    sSource   := copy( sSource, 1, iPosition-1 ) + sReplace + copy( sSource, iPosition+length(sSearch), length(sSource)-iPosition );
    iPosition := Pos( sSearch, sSource );
  end;
  Result := sSource;
end;

Works for me!!

Regards Jacco
0
 
LVL 1

Expert Comment

by:BlackDeath
ID: 1339216
function Replace(s: string; sfrom, sto: string): string;
begin
  while Pos(sfrom, s) > 0 do begin
    s := Copy(s, 1, Pos(sfrom, s) - 1) + sto +
         Copy(s, Pos(sfrom, s) + Length(sfrom),
           Length(s) - Pos(sfrom, s) + Length(sfrom) - 1);
  end;
  Result := s;
end;

// replaces sfrom in s with sto

looks awful, can be done much better, but is understandable.

Black Death.
0
 
LVL 1

Expert Comment

by:BlackDeath
ID: 1339217
OH MY GOD!

jacco - extremely sorry for this!!!
hit me!!!
i don't know how i could have missed your answer.
pleez don't be angry at me, i'm afraid i've gone blind...
or am i already dead?

mercy - merci.

have a nice day y'all.
that's it for me. i'm gonna go back to sleep...

so long,

Black Death.

0
 
LVL 1

Expert Comment

by:BlackDeath
ID: 1339218
whoops:
you should add

if sfrom=sto then
  Exit;

as first statement of the proc,
otherwise you would waste *_infinite_* runtime...

Black Death.
0
 
LVL 1

Expert Comment

by:BlackDeath
ID: 1339219
ohman:

if sfrom = sto then begin
  Result := s;
  Exit;
end;

Black Death.
0
 
LVL 1

Expert Comment

by:BlackDeath
ID: 1339220
that's for your's too, jacco...
0
 
LVL 10

Expert Comment

by:Jacco
ID: 1339221
BlackDeath:

You're right!

I'll add it in my library source!

Regards Jacco
0
 
LVL 10

Expert Comment

by:Jacco
ID: 1339222
The function then becomes:

function StrTran(sSource, sSearch, sReplace: string ): string;
var
  iPosition: integer;
begin
  if sReplace<>sSearch then begin
    iPosition := Pos( sSearch, sSource );
    while iPosition > 0 do begin
      sSource   := copy( sSource, 1, iPosition-1 ) + sReplace + copy( sSource, iPosition+length(sSearch), length(sSource)-iPosition );
      iPosition := Pos( sSearch, sSource );
    end;
  end;
  Result := sSource;
end;

I try to prevent using exit to much
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

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…
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…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month13 days, 15 hours left to enroll

800 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