Solved

Insert TAB into the string.

Posted on 2003-11-12
10
1,947 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:raymng
  • 5
  • 3
  • 2
10 Comments
 
LVL 6

Expert Comment

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

Expert Comment

by:kretzschmar
Comment Utility
too late :-(
0
 
LVL 6

Expert Comment

by:GloomyFriar
Comment Utility
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
 
LVL 27

Accepted Solution

by:
kretzschmar earned 150 total points
Comment Utility
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
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 1

Expert Comment

by:JackNaif
Comment Utility
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
Comment Utility
>'First part'#9'Second Part'
It's not readable from my point of view.
0
 
LVL 1

Expert Comment

by:JackNaif
Comment Utility
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
Comment Utility
>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
Comment Utility
#58#45#41

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

Featured Post

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

Join & Write a Comment

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…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

728 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

9 Experts available now in Live!

Get 1:1 Help Now