Solved

Insert TAB into the string.

Posted on 2003-11-12
10
2,012 Views
Last Modified: 2008-03-10
A string = '12xcvfgr12dfgfrtfgg12werd12......'

I need to insert a TAB before '12' in the string except the first '12'.

Resulting string = '12xcvfgr(TAB)12dfgfrtfgg(TAB)12werd(TAB)12......'

I need the source code, thank you!

raymng
0
Comment
Question by:Raymond
  • 5
  • 3
  • 2
10 Comments
 
LVL 6

Expert Comment

by:GloomyFriar
ID: 9732593
string = '12xcvfgr'+#9+'12dfgfrtfgg'+#9+'12werd'+#9+'12......'
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9732712
too late :-(
0
 
LVL 6

Expert Comment

by:GloomyFriar
ID: 9732747
function ProcessString(src: string): string;
var i: integer;
begin
  Delete(src, 1, 2);
  Result := '12';
  repeat
    i := Pos('12', src);
    Result := Result + Copy(src, 1, i - 1) + #9 + '12';
    Delete(src, 1, i + 1);
  until i = 0;
  Result := Result + src;
end;
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 27

Accepted Solution

by:
kretzschmar earned 150 total points
ID: 9732788
why not use stringreplace like

procedure TForm1.Button1Click(Sender: TObject);
var s : string;
begin
  s := edit1.text;
  s := stringReplace(s,'12',#9+'12',[rfReplaceAll]);
  delete(s,1,1);
  memo1.text := s;
end;


meikl ;-)

0
 
LVL 6

Expert Comment

by:GloomyFriar
ID: 9733285
There is a bug in my previous code ;-)
Here is the tested version:

function ProcessString(src: string): string;
var i: integer;
begin
  Delete(src, 1, 2);
  Result := '12';
  while True do begin
    i := Pos('12', src);
    if i = 0 then break;
    Result := Result + Copy(src, 1, i - 1) + #9 + '12';
    Delete(src, 1, i + 1);
  end;
  Result := Result + src;
end;
0
 
LVL 1

Expert Comment

by:JackNaif
ID: 9735380
You don't need the '+' between a constant string within ' ' and a #9.

'First part'#9'Second Part'  would also be all right. (You might prefer to leave the + for readability though...)
0
 
LVL 6

Expert Comment

by:GloomyFriar
ID: 9738410
>'First part'#9'Second Part'
It's not readable from my point of view.
0
 
LVL 1

Expert Comment

by:JackNaif
ID: 9740428
The definition for "readability" is such an elusive one... <sigh>

IMHO it might be preferable to skip the '+' when you have a lot of #xxx chars and too many '+' would make the string unconfortably long. (Besides, if you put a lot of #xxx in a string, it's already a hieroglyphic, so who cares any more about readability anyway...)   =)
Also, things like 'First line' + #13#10 + 'Second line'  should be considered -again, IMHO- preferable to 'First line' + #13 + #10 + 'Second line'.

But I do agree it is normally preferable to leave the '+'.
0
 
LVL 6

Expert Comment

by:GloomyFriar
ID: 9741634
>when you have a lot of #xxx chars and too many '+' would make the string unconfortably long.
agree.
0
 
LVL 1

Expert Comment

by:JackNaif
ID: 9741763
#58#45#41

(Isn't it the longest smiley ever?)
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Machine not responding during CopyFile() 3 98
Dev Express grid collapse 2 44
How to build JSON File in Delphi 6 3 32
Delphi: sending SMS on android platform 1 17
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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 I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

813 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

12 Experts available now in Live!

Get 1:1 Help Now