Will it possible to pass the value of a string to another, but then pass to another. Keeping data?
Ex. Dim A as String
Dim B as String
Dim C as String
B = A
NOW if i change value of A Obiously C and B Changes.
But what if i want to B keeps the last version of A, and C aquires the new value of A?
Have you tied this in a quick little app yet ?
I’d suggest you do that
As far as strings go they are handled as “value types”
If that is true, I have quite some changes to make.
Reference types (like instance of objects) would because they might all refer to the same object
ie/ if you do
dim d as new date
dim a as date = d
because a and d refer to the same instance and so if you change a.totalseconds then d.totalsseconds also “changes”
strings are not reference types
I was trying to encourage gerardo to try things and read the references before asking here
Thats usually a good strategy
At least that way you can ask this like
“I tried this and this seems to work like … and the references aren’t clear what should happen”
A lot of the people frequenting the forums appreciate that you’ve done or tried to do that kind of “self help”
Keep in mind too that strings are immutable, i.e., you cannot change them. All you can do is create and assign new ones.
To put it another way, how would you change a string? If it were a MemoryBlock, you could modify a byte, but a String has no such tool. You can’t, for example, do something like
s.Mid( 1, 1 ) = "a". All you can do is replace one string with another.
a = "some string"
b = a // "some string"
a = a.Left( 4 ) // b = "some string", but a is now a new string, "some"
b = b.Left( 4 ) // b now = "some" too, and "some string" is gone
In this way, you can think of a string as an immutable object. That object can be assigned to multiple variables, but can never be modified. When nothing refers to that string anymore, it goes away.
(This underscores another point: Assigning one string variable to another does not copy the string, merely passes the reference, just like assigning one Date variable to another.)
I have been using strings without thinking of their nature for too long. You are right of course.
Such thing as
Mid(s,0,1) = "z" is not possible.
The implementation is so seamless, it’s easy to not think about.
The implementation makes them seem more like value types than immutable objects - which is nice
You don’t have to ever call NEW on a string or worry about when its released
You cant assign NIL like you could if it were an object reference
Appearances to you are that they are value types
Its an internal detail that leaked out in a few spots that they are immutable objects