« Lotus Open Labs in Dallas and Houston starting next week | Main| Early Mac Notes 8.5 beta download appears to be a Solaris server install »

Dim myData as String * 256

Category
Bookmark : del.icio.us  Technorati  Digg This  Add To Furl  Add To YahooMyWeb  Add To Reddit  Add To NewsVine 

You C-coders have known about this for years I'm sure. Many of you Lotusscript types probably have known about this for years. Hell, once upon a time, I probably knew this. But yesterday, I ran across a line of code like this and was intrigued... "What the heck is that?"

If you peruse help for the String data type, you find:

The declaration of a string variable uses this syntax:

Dim varName As String [* num]

The optional num argument specifies that varName is a fixed-length string variable of num characters. A fixed-length string variable is initialized to a string of null characters (the character Chr(0)).

When you assign a string to a fixed-length string variable, LotusScript truncates a longer string to fit into the declared length. It pads a shorter string to the declared length with trailing spaces.

Fixed-length strings are often used in declaring data structures for use in file I/O or C access.

I don't know about you, but I don't know how many times I've written some kind of padding function so that my data was exactly the length I needed, whether for some kind of data export, or funky display table thing.

Oh well, old dogs can learn new tricks.

Comments

Gravatar Image3 - Just as I suspected. You big time C types have known about this all along. That's okay, keep your dirty secrets. See if I care. I'll have my revenge, wha ha ha ha!

Gravatar Image2 - Yup. Fixed length strings dont have the "takes ages to add two strings together" problem that "normal" strings have. When you add a string to another string, it creates a third and has to copy the whole lot in memory - quite expensive.

Its the same as a bunch of other languages in that respect - java is another.

I tend to just use the fixed length stuff for C-API calls...

---* Bill

Gravatar Image1 - Yeah, baby! Performs faster in many situations, too, as the LS interpreter always knows exactly how much storage the string consumes, doesn't have to do "strlen()" type operations, and doesn't have to realloc things.

In the right situations, fixed-length strings rock. Most of the rest of the time, though, they're not terribly oonvenient

Post A Comment

:-D:-o:-p:-x:-(:-):-\:angry::cool::cry::emb::grin::huh::laugh::lips::rolleyes:;-)