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

= September 6 =

Can (non-Visual) BASIC address individual characters within a $string?
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)
 * IIRC, you can assign to, so it would be  , or something similar. Handling errors and wrap-around is left as an exercise for the reader and OP. If   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)
 * 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)
 * 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 PB
 * 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)