Solved

How to do this?

Posted on 1998-09-10
12
229 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
  • 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

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…
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

778 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