[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Insert TAB into the string.

Posted on 2003-11-12
10
Medium Priority
?
2,332 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 600 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

650 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