[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to do this?

Posted on 1998-09-10
12
Medium Priority
?
236 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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 I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month20 days, 12 hours left to enroll

865 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