Solved

Insert TAB into the string.

Posted on 2003-11-12
10
2,159 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
Technology Partners: 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

707 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