RIGHT$: Your String Tail-End Tamer

RIGHT$: Your String Tail-End Tamer

Need to grab the end of a word, phrase, or sentence? Want to extract the last few characters from a string? Look no further than the RIGHT$ command, your string tail-end tamer! This handy function lets you precisely slice off the rightmost part of a string, leaving you with just the characters you need. It's like having a tailor-made tool for trimming your text!

Syntax

RIGHT$(<string>, <length>)

Where: - <string>: The string you want to extract characters from. - <length>: The number of characters you want to keep, counting from the right end of the string.

Applications

The RIGHT$ function is your go-to tool when:

  • Extracting file extensions: Isolate the ".txt", ".prg", or other extensions from filenames.
  • Getting the last part of a word: Grab the suffix of a word, like "-ing" or "-ed".
  • Formatting data: Extract the last few digits of a number, like a phone number extension.
  • Validating input: Check if the end of a user's input matches a specific pattern.

Code Examples

1. Simple Character Extraction:

10 A$ = "Commodore 64"
20 B$ = RIGHT$(A$, 2)  :rem B$ stores "64"
30 PRINT B$             :rem Output: 64

This example extracts the last two characters ("64") from the string "Commodore 64".

2. Extracting File Extension:

10 INPUT "ENTER A FILENAME: "; N$
20 F$=RIGHT$(N$,3)  :REM EXTRACT THE EXTENSION
30 PRINT "FILE EXTENSION: "; F$

This snippet demonstrates how to use RIGHT$ in conjunction with INSTR and LEN to determine the file extension of a user-inputted filename.

RIGHT$ in the Wild: The Phone Number Formatter

Imagine you're writing a program to manage contact information. RIGHT$ could help you extract the last four digits of a phone number, which might be a useful way to display or organize the data.

Don't let your strings get too long-winded! With RIGHT$ in your toolbox, you can easily snip them down to size, extracting just the information you need from the right end. It's a simple yet powerful function that can streamline your string manipulations and make your Commodore 64 programs more efficient. So embrace the precision of RIGHT$ and become a master of string trimming!


Privacy Policy

Let's be honest, we collect some data. But we promise not to sell it, we'll mostly use it to improve our service. You can read the nitty-gritty details below, but be warned, it uses big words that lawyers like (we don't judge).

By using our service, you agree to this privacy policy. This disclaimer strikes a balance between lightheartedness and informing users that they should still read the full privacy policy if they choose.