Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concatenation with empty string raises ERR:INVALID DIM

In TI-BASIC, the + operation is overloaded for string concatenation (in this, if nothing else, TI-BASIC joins the rest of the world).

However, any attempt to concatenate involving an empty string raises a Dimension Mismatch error:

"Fizz"+"Buzz"
        FizzBuzz 
"Fizz"+""
           Error
""+"Buzz"
           Error
""+""
           Error

Why does this occur, and is there an elegant workaround? I've been using a starting space and truncating the string when necessary (doesn't always work well) or using a loop to add characters one at a time (slow).

like image 619
Khuldraeseth na'Barya Avatar asked Oct 26 '25 14:10

Khuldraeseth na'Barya


1 Answers

The best way depends on what you are doing.

If you have a string (in this case, Str1) that you need to concatenate with another (Str2), and you don't know if it is empty, then this is a good general-case solution:

Str2
If length(Str1
Str1+Str2

If you need to loop and add a stuff to the string each time, then this is your best solution:

Before the loop:

" →Str1

In the loop:

Str1+<stuff_that_isn't_an_empty_string>→Str1

After the loop:

sub(Str1,2,length(Str1)-1→Str1

There are other situations, too, and if you have a specific situation, then you should post a simplified version of the relevant code.

Hope this helps!

like image 163
iPhoenix Avatar answered Oct 29 '25 15:10

iPhoenix