String Manipulation: Basics

Welcome to our lesson on the basics of string manipulation in AutoLISP! Strings, as sequences of characters, play a crucial role in almost all programming tasks. Whether you’re processing user input, displaying messages, or handling file names, understanding how to manipulate strings is essential. Today, we’re going to delve deep into some fundamental string manipulation functions in AutoLISP that will greatly enhance your programming capabilities.

Learning Outcomes

By the end of this lesson, students will be able to:

  • Identify and understand the basic string manipulation functions in AutoLISP.
  • Apply these functions to perform common string operations effectively.
  • Construct and analyze complex string expressions using a combination of the functions.
  • Integrate string manipulation functions into larger AutoLISP programs for practical applications.


Definition: Converts the first character of a string to its ASCII value.


(ascii string)

Example 1:

(ascii “A”)
; This will return 65

This code converts the character “A” to its ASCII value, which is 65.

Example 2:

(ascii “hello”)
; This will return 104

The function takes the first character of “hello”, which is “h”, and returns its ASCII value, 104.


Definition: Converts an ASCII value to its corresponding character.


(chr integer)

Example 1:

(chr 65)
; This will return “A”

This code converts the ASCII value 65 to its corresponding character, “A”.

Example 2:

(chr 104)
; This will return “h”

The function converts the ASCII value 104 to its character equivalent, “h”.


Definition: Converts all the alphabetic characters in a string to uppercase.


(strcase string)

Example 1:

(strcase “Hello”)
; This will return “HELLO”

This function converts all characters in “Hello” to uppercase.

Example 2:

(strcase “wOrld”)
; This will return “WORLD”

It changes all the characters in “wOrld” to uppercase.


Definition: Concatenates two or more strings into a single string.


(strcat string1 string2 …)

Example 1:

(strcat “Hello” ” ” “World!”)
; This will return “Hello World!”

This code combines three strings into one.

Example 2:

(strcat “CAD” ” ” “Design”)
; This will return “CAD Design”

This function joins “CAD” and “Design” with a space in between.


Definition: Returns the length of a string.


(strlen string)

Example 1:

(strlen “Hello”)
; This will return 5

This function returns the length of the string “Hello”, which is 5 characters.

Example 2:

(strlen “AutoLISP”)
; This will return 8

It calculates the length of “AutoLISP”, which has 8 characters.


Definition: Extracts a substring from a string, starting at a specified position.


(substr string start [length])

Type: Integer = A positive numerical value represents the starting position within the ‘str’ variable, with the first character in the string being designated as position 1.

Type: Integer = A positive numerical value to provide to indicate the number of characters to be searched within the ‘str’ variable. If the ‘length’ is not explicitly mentioned, the search for the substring extends all the way to the end of ‘str’.

Example 1:

(substr “Hello World!” 7 5)
; This will return “World”

This function extracts “World” from “Hello World!” starting at the 7th character.

Example 2:

(substr “Programming” 1 4)
; This will return “Prog”

It extracts the first four characters, “Prog”, from the string “Programming”.

In conclusion, mastering basic string manipulation in AutoLISP is a stepping stone to more complex programming tasks. These foundational functions are versatile tools that will enable you to handle text in your programs effectively. Remember to practice these functions regularly, and always strive to understand the underlying principles.