Solved

Insert TAB into the string.

Posted on 2003-11-12
10
2,086 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
[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
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
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!

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

726 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