Solved

How to do this?

Posted on 1998-09-10
12
223 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
 

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now