Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7946489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:09:57+00:00 2026-06-04T01:09:57+00:00

I want to insert a char into every possible position of s string except

  • 0

I want to insert a char into every possible position of s string except start and end.
e.g.

abc
I want to have 
a-bc
ab-c
a-b-c

Below is my test, but not correct:

procedure TForm1.Button2Click(Sender: TObject);
var
start, i,j,k,position,loop: integer;
laststart,lastend:integer;
c,item,stem:string;
str, prefix:string;
begin
str:='abcd';
memo1.clear;
memo1.Lines.Add(str);
laststart:=0;
lastend:=memo1.lines.count-1;
position:=0;
prefix:='';
loop:=0;
while loop<=length(str)-1 do
  begin

    for j:= laststart to lastend do
    begin
    item:=memo1.lines[j];
        for k:=length(item) downto 1 do
        begin
            if item[k]='-' then
            begin
            position:=j;
            break;
            end;
         end;  //for k
   prefix:=copy(item,1,position);
   stem:=copy(item,position+1, length(item));

        for start:=1 to length(stem)-1 do
        begin
        c:=prefix+copy(stem,1,start)+'-'+
        copy(stem, start+1,length(stem));
        memo1.lines.add(c);
        end;
     end; //for j
    laststart:=lastend+1;
    lastend:=memo1.Lines.Count-1;
inc(loop);
end; //end while

end;

it outputs:

abcd
a-bcd
ab-cd
abc-d
a--bcd // not correct
a-b-cd
a-bc-d
ab--cd //incorrect
ab-c-d
abc--d  //incorrect
a--bc-d //incorrect

I feel the maximum possible breaks is lenth(str)-1, abc->most possible is insert 2 ‘-‘ (twice). Is this correct?

And are there other faster ways to do it?

Thanks a lot.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T01:10:00+00:00Added an answer on June 4, 2026 at 1:10 am

    This works:

    procedure TForm4.Button1Click(Sender: TObject);
    var
      S: string;
      N: integer;
      Marker: cardinal;
      MaxMarker: cardinal;
      Str: string;
      i: Integer;
    begin
      S := Edit1.Text;
      N := length(S);
      Marker := 0;
      MaxMarker := 1 shl (N - 1) - 1;
    
      Memo1.Clear;
      Memo1.Lines.BeginUpdate;
    
      for Marker := 0 to MaxMarker do
      begin
        Str := S[1];
        for i := 2 to N do
        begin
          if (Marker shr (N-i)) and 1 <> 0 then
            Str := Str + '-';
          Str := Str + S[i];
        end;
        Memo1.Lines.Add(Str);
      end;
    
      Memo1.Lines.EndUpdate;
    end;
    

    Screenshot

    As you can see, it works by using binary representation of numbers:

    t e s t
     0 0 0
     0 0 1
     0 1 0
     0 1 1
     1 0 0
     1 0 1
     1 1 0
     1 1 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I want to insert into a database column of type char(2) from C#.
I am writing a simple query as below const char *sql = insert into
I have vector with 6 numbers, which I want insert to list and add
I want to insert 10,00,000 rows into the database, but the it takes too
I want to insert data to database. I have a table, named member that
I want to insert another automatically generated UL before the end tag for the
I want to insert the current date/time into my xml feed using Rails Builder.
I want to insert one object like $('<p>Test</p>').prependTo('#TB_window'); just whenever #TB_window object is created.
I made iPad application in which, I want to insert record into database table,
I have a file with contents something like this: INSERT INTO table VALUES (NULL,'°

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.