From the course: Learning AutoLISP & Visual LISP

Function: strlen - AutoCAD Tutorial

From the course: Learning AutoLISP & Visual LISP

Start my 1-month free trial

Function: strlen

- [Instructor] What about when we're working with a string and we want to know its exact length? How many characters are there in this string? Let's use string length or STRLEN, the list function to do so. The simple argument that's required is our string. I'm going to provide the results of a variable named SAVENAME, and find out the string length. In this case if the string length is zero, and then I know that the drawing has not been saved yet. There is no string at all in this variable. Now if I assign a different variable, such as CLayer, this string length will be the length of my layer. What is my layer? Layer zero. And therefore there is only one character or piece of text in that layer name. Let's go ahead and put this to work. If a condition is met, what is the condition? I want to find out if the drawing has been saved. There's my condition. If the variable, save name, has a length that is equal to zero, then I know that the drawing has not been saved. Now if it's false, or it is longer than zero, that means the drawing has been saved. And is a named file. So go ahead and inspect. It says drawing has not been saved, why is that? Notice I'm working in a brand new drawing named drawing one. Which really isn't a name yet because we haven't saved it. But if I save the file and we put it and give it a name such as Lynda.com, and we inspect our code again, the drawing has been saved. So we see the power of string length. It can be used in relation with other variables. We can check to make sure that the length is the correct length. Really it's often times used right before we combine text to make sure we are combining the right text together.

Contents