Are VBA strings immutable?

I know that .NET strings (and therefore VB.NET) are immutable. However, I am using VBA 7.0 in Excel 2010. Are the rows immutable? I do a lot of string processing and for small amounts, some (direct) string manipulations are fine, but I worry that it will not scale - since each additional character moved from one line to another can create another instance of the line.

+7
string vba excel-vba
source share
2 answers

VBA strings are immutable.

As with VB.NET, it is not possible to “replace a part” or “attach to” a line without creating a new line. Regardless of whether it is important, as modern computers are pretty fast simple - it depends on the actual algorithm, data and environment.


Unlike the .NET documentation, such a reference to behavior for VBA [becomes] difficult to track. From MS-VBAL: 2.1 Data Values ​​and Value Types , We Find This Rare Little Stone

Individual data values ​​are immutable. This means that there are no specific mechanisms in a VBA environment that can cause a data value to change to another data value.

where Rows represent "individual data values."

+3
source share

They are immutable, unless they exhibit volatile behavior, then they are not.

For example, assignment via mid$() much faster than the usual assignment of a new line from an assignment.

 Dim s As String s = "ABC" Debug.Print s, StrPtr(s) '// -> ABC 122899836 Mid$(s, 1, 1) = "Z" Debug.Print s, StrPtr(s) '// -> ZBC 122899836 s = "??" & Right$(s, 1) Debug.Print s, StrPtr(s) '// -> ??C 196635748 
+6
source share

All Articles