User Tools

Site Tools


changing_20the_20case_20of_20a_20string

Changing the case of a string

by Jon Ripley, May 2006

The FNUSING library supplied with BBC BASIC for Windows contains the functions FNlower and FNupper which can be used to change the case of a string to lower case or UPPER CASE respectively. These are described in the main help documentation here. Alternatively the Windows API calls “CharUpperBuff” and “CharLowerBuff” can be used to manipulate the case of characters in a string.

Changing the whole string


To change the case of the string My$ to upper case use code similar to the following:

        SYS "CharUpperBuff", !^My$, LEN(My$)


To change the case of the string My$ to lower case use code similar to the following:

        SYS "CharLowerBuff", !^My$, LEN(My$)


Changing a portion of a string


To change characters at the start of the string to upper case use code similar to the following:

        SYS "CharUpperBuff", !^My$, Num%

Here My$ is the string you want to alter and Num% is the number of characters to change. The value of Num% must be less than or equal to the length of the string.

To change characters at the end of the string to lower case use code similar to the following:

        SYS "CharLowerBuff", !^My$ + LEN(My$) - Num%, Num%

Here My$ is the string you want to alter and Num% is the number of characters to change. The value of Num% must be less than or equal to the length of the string.

To change the case of characters in the middle of the string to upper case use code similar to the following:

        SYS "CharUpperBuff", !^My$ + Pos%, Num%

Here My$ is the string you want to alter, Pos% is the position of the first character in the string to alter and Num% is the number of characters to change. The sum of Num% and Pos% must be less than or equal to the length of the string.

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
changing_20the_20case_20of_20a_20string.txt · Last modified: 2024/01/05 00:22 by 127.0.0.1