Wikipedia:Reference desk/Archives/Computing/2020 September 6
Appearance
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)
- IIRC, you can assign to
MID$()
, so it would beMID$(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. IfMID$()
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.[1][2][3][4] Graeme Bartlett (talk) 23:55, 7 September 2020 (UTC)
- Every BASICs I have used allows assigning to MID$(). Even gwbasic can it, see [[5]] 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)
- Every BASICs I have used allows assigning to MID$(). Even gwbasic can it, see [[5]] 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
- None of the BASICs I have used allows assigning to MID$(), as it returns a value.[1][2][3][4] Graeme Bartlett (talk) 23:55, 7 September 2020 (UTC)