Edge Rewrite
// HTMLRewriter · presentation

This page was redesigned at the edge.

Cloudflare fetched the original article and streamed it through HTMLRewriter to apply an entirely new visual system without rebuilding the source page.

Jump to content

Wikipedia:Reference desk/Archives/Computing/2020 September 6

From Wikipedia, the free encyclopedia
Computing desk
< September 5 << Aug | September | Oct >> September 7 >
Welcome to the Wikipedia Computing Reference Desk Archives
The page you are currently viewing is a transcluded archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages.


September 6

[edit]

Can (non-Visual) BASIC address individual characters within a $string?

[edit]

Was trying to remember if there was an elegant way for BASIC to address the individual characters within a variable string. Something like:

10: INPUT A$
20: PRINT "Pick a letter to bump!"
30: INPUT N

with line 40 choosing the Nth character of A$ and incrementing it by one ASCII, so for instance if A$ was "AAAAA" and N was 3 the output would be "AABAA". I can envision a way to do it inputting each character separately (10: INPUT A$, 11: INPUT B$, etc etc), then some disgusting IF THEN mess to convert each individual string variable to a number, then some more disgusting IF THEN mess to convert the numbers back to letters, but that's pretty gross even for BASIC! 96.255.2.209 (talk) 13:58, 6 September 2020 (UTC)reply

IIRC, you can assign to MID$(), so it would be MID$(A$,N,1)=CHR$(1+ASC(MID(A$,N,1))), or something similar. Handling errors and wrap-around is left as an exercise for the reader and OP. If MID$() isn't assignable, you will have to build a string with the part before the original, the incremented letter, and the part after. LongHairedFop (talk) 15:32, 6 September 2020 (UTC)reply
None of the BASICs I have used allows assigning to MID$(), as it returns a value. Graeme Bartlett (talk) 23:55, 7 September 2020 (UTC)reply
Every BASICs I have used allows assigning to MID$(). Even gwbasic can it, see [] but then it is called a statement and not a function of course.2003:F5:6F00:ED00:D3A:2C30:3941:92C6 (talk) 16:23, 8 September 2020 (UTC) Marco PBreply
Some BASICs don't have MID$() in any form (or for that matter LEFT$() and RIGHT$()), instead they use string slicing. Martin of Sheffield (talk) 21:32, 8 September 2020 (UTC)reply