Random access to the characters in a string?

May 20, 2008
11,411
99
Syracuse, NY, USA
Is there an easy way to randomly access, and change, any character (by position) in a string?

For example, change "----" to any of "*---", "-*--", "--*-", "---*".
 
May 20, 2008
3,515
4
Elkridge, MD, USA
---- Original Message ----
From: vefatica
To: ESFabian@zenge.org
Sent: Saturday, 2011. February 19. 22:58
Subject: [Support-t-2617] Random access to the characters in a string?

| Is there an easy way to randomly access, and change, any character
| (by position) in a string?
|
| For example, change "----" to any of "*---", "-*--", "--*-", "---*".

No easier than in C - you need to extract the parts of the string to be retained (uisng @left and @right) and concatenate the three parts (retained left substring, new substring, retained right substring). There is no equivalent to the Fortran77 statement
x[3:3]='*'
(replace the substring starting at the third character and ending at the third character with the asterisk character). A good candidate for a plugin or - better yet - a new internal function! Such a new function should allow pure insertion and pure deletion, too, simply by specifying the width of the substring to be replaced or that of the replacement substring as 0, resp. BTW, it is best to treat individual characters as one of the two special cases of strings, i.e., strings of lengths 0 and 1.
--
Steve
 
May 20, 2008
11,411
99
Syracuse, NY, USA
On Sun, 20 Feb 2011 08:41:20 -0500, Steve Fabian <> wrote:

|| For example, change "----" to any of "*---", "-*--", "--*-", "---*".
|
|No easier than in C - you need to extract the parts of the string to be retained (uisng @left and @right) and concatenate the three parts (retained left substring, new substring, retained right substring). There is no equivalent to the Fortran77 statement
| x[3:3]='*'
|(replace the substring starting at the third character and ending at the third character with the asterisk character). A good candidate for a plugin or - better yet - a new internal function! Such a new function should allow pure insertion and pure deletion, too, simply by specifying the width of the substring to be replaced or that of the replacement substring as 0, resp. BTW, it is best to treat individual characters as one of the two special cases of strings, i.e., strings of lengths 0 and 1.

Yes. I wrote a little plugin last night. In C you can just string = L'c'.
It must be many times faster than copying the left end, then the new character,
then the right end (which I did with a user-defined function).

So far the plugin is very straightforward.

Code:
v:\> do i=0 to 3 ( echo %@strchr[----,%i,*] )
*---
-*--
--*-
---*

Are there any suggestions for it?
 
May 20, 2008
3,515
4
Elkridge, MD, USA
---- Original Message ----
From: vefatica
...
| Yes. I wrote a little plugin last night.
| In C you can just string = L'c'.
Unlike C, where you can only replace a single character without a function call, in Fortran you can replace a whole section of a string as string(a:b)='xyzw'; IIRC some versions of BASIC also have a like operator.

| It must be many times faster than copying the left end, then the new
| character,
| then the right end (which I did with a user-defined function).

Sorry, I have given you bad advice! Loop at HELP topic "f_subst.htm"! It just needs some examples..
--
Steve
 
May 20, 2008
11,411
99
Syracuse, NY, USA
On Sun, 20 Feb 2011 18:32:40 -0500, Steve Fabian <> wrote:

|Sorry, I have given you bad advice! Loop at HELP topic "f_subst.htm"! It just needs some examples..

Thanks. That accomplishes my original goal. My plugin (now @overwrite[]), as
it stands now, does the same thing but will stop rather than lengthen string2.
 
Similar threads
Thread starter Title Forum Replies Date
vefatica WAD @RANDOM Support 27
C How to? Select 100 random pictures from 30,000 Support 8
ehab aboudaya Random Register reminder on new tab annoyance Support 4
Jesse Heines Access Denied errors in TCC 27 Support 9
Jay Sage Directory Alias Access to FTP Servers Support 2
vefatica "Access denied" messages from DO Support 3
O TPIPE: Error -Can´t access textpipeengine.dll Support 24
C How to? Setting up SMTP access for Yahoo with TCMD v20 Support 7
dcantor Unable to access help Support 9
P Access denied TakeCommand.19.0.key Support 2
D How to? How to access iPhone from tcmd.exe? Support 1
vefatica TPIPE access violations are back Support 2
vefatica TPIPE access violation again Support 1
vefatica TPIPE: Access violation Support 5
S WAD Cannot access mapped drive in 64b Win7 Support 15
C registration proboem if no internet access given Support 0
cgunhouse TPIPE: Error - Can't access textpipeengine.dll Support 14
P Can't access textpipeengine.dll Support 11
Q TCC: (Sys) The process cannot access the file because it is being used by another process. Support 0
C Cannot register v12.10 without Internet access Support 19
S How to access array elements? Support 5
S FTP site; IFTP access Support 10
Roedy tccbatch Windows 7 "access is denied" Support 4
T Access violation upon TC startup Support 2
M Testing my e-mail access Support 1
mscheuner How to access XML *attributes* using XPath Support 3
p.f.moore Broken email access to these forums - finally giving up Support 4
K_Meinhard Email access, again Support 2
K_Meinhard email access Support 6
rconn Email access Support 6
C access denied problem under Vista Support 5
R WAD Unusable state when using Chinese characters Support 3
C TEE command appending null characters to output Support 6
D Regexes and escape characters Support 5
vefatica Quoting file names with special characters? Support 7
vefatica How to? Add real <ESC> characters with TPIPE Support 2
C Erase all characters left or right from cursor location Support 2
J Escaped Characters and Variables Support 2
Joe Caverly Unicode, Codepage 437, and line characters Support 3
gschizas Fixed Using codepage 65001 (UTF-8) breaks non-ASCII characters Support 8
vefatica Display of special characters in aliases. Support 25
J Python: TCC command line parsing removes '=' equal sign characters Support 4
C filemasks over 172 characters fail Support 5
redwdc TCC.exe opens to 11 characters x 3 rows Support 1
G Selection characters with mouse double-click Support 3
R Function #IDOW returns only 2 characters Support 10
krischik WAD Tee printing Chinese characters Support 7
Alexander How to? how can I use Cyrillic characters in the Echo command? Support 8
jadaml Echo unicode characters from UTF-8 Batch files? Support 1
V Fixed CD ~ has trash characters in it Support 5

Similar threads