bug-apl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-apl] A better way to insert characters into a character vector?


From: Nick Lobachevsky
Subject: Re: [Bug-apl] A better way to insert characters into a character vector?
Date: Fri, 28 Aug 2015 19:35:47 +0200

I use the following idiom for string insertion.  It works reasonably
well when the integer width is small, 1 or 2 bytes.

But first, let's change the problem slightly get rid of the "e", then
insert "www" after the "l" in "alx".  This solution is for origin 1.

      a←'alx'
      b←'www'
      (a,b)[⍋(⍳⍴a),(⍴b)⍴2]

⍳⍴a is 1 2 3
2 is the position of the "l".  The "www" will be inserted after this position.
(⍴b)⍴2 is 2 2 2
⍋(⍳⍴a),(⍴b)⍴2 is 1 2 4 5 6 3

This technique works very well with multiple insertions.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]