String case: Difference between revisions

Added Commodore BASIC.
No edit summary
(Added Commodore BASIC.)
Line 531:
Upper case: ALPHABETA
Title case: AlphaBETA</pre>
 
==={{header|Commodore BASIC}}===
 
The example here is based on AppleSoft BASIC, however, Commodore machines have a slightly different interpretation of ASCII:
 
* On a number of Commodore machines, the default character set at startup is uppercase letters with graphic symbols. In this instance, standard ASCII codes apply, which means printing the result of <code>ASC("A")</code> returns <code>65</code>, and printing the result of <code>ASC("&spades;")</code> (SHIFT-A) returns 193. (Not 97... More on this below.)
* However, on many of these Commodore machines, the character mode can be changed(&dagger;) to an alternate set of glyphs which consists of lowercase letters as well as uppercase letters. When this happens, the former uppercase letter glyphs are replaced with lowercase letter glyphs, and the graphics glyphs are replaced with uppercase letter glyphs. This maintains intuitive use of the computer where typing an uppercase letter is accomplished by holding the SHIFT key while pressing the letter, but the downside is that now the equivalent ASCII codes are reversed: 65 equates to a lowercase "a" (should be 97), and 97 equates to an uppercase "A".
* In addition to all of this, characters 192 through 255 are duplicates of other characters in the lower realms of the table. This allows one to easily use bit 7 as a flag for a shifted character. This is perhaps one reason why BASIC's <code>ASC</code> returns values for shifted letters starting at 193. In any case, it needs to be accounted for, and actually makes this task simpler.
 
 
&dagger; Exceptions to the above would be early PET 2001 models that either had no lowercase letters at all, or had upper and lowercase, but were locked into traditional ASCII encoding. The code example will not behave as expected on these models.
 
It should be noted that the program starts by sending a control code 14 to the display immediately after clearing the screen, which ensures that the computer is displaying the mixed lowercase/uppercase character set, otherwise the output will be a mix of uppercase letters and graphics.
 
'''Code Example'''
<lang commodorebasic>10 rem string case
15 rem rosetta code
20 s$="alphaBETA"
30 print chr$(147);chr$(14)
40 print "The original string is:"
41 print:print tab(11);s$
50 up$="":lo$=""
55 for i=1 to len(s$)
60 c=asc(mid$(s$,i,1))
65 up$=up$+chr$(c or 128)
70 lo$=lo$+chr$(c and 127)
75 next i
80 print:print "Uppercase: ";up$
90 print "Lowercase: ";lo$</lang>
 
{{output}}
<pre>
The original string is:
alphaBETA
Uppercase: ALPHABETA
Lowercase: alphabeta
ready.
&#9608;</pre>
 
==={{header|IS-BASIC}}===
113

edits