string conversion, but returning a new string object

  • Thread starter Thread starter John A Grandy
  • Start date Start date
J

John A Grandy

the conversion methods on the VB.NET String objects are of course very
useful ... but it would seem that one of the most common needs is not
properly addressed ...

if I do

Dim s As String
s = "I acTually Want the case To BE like THis"
TextBox1.Value = s.ToUpper()

maybe I get what I want in that particular text-box .... but my String
object has lost its original case ...

Of course, I can do

Dim s As String
Dim s1 As String
s = "I acTually Want the case To BE like THis"
s1 = s
TextBox1.Value = s1.ToUpper()

but that's a couple extra lines of code.

StrConv() is no better because it also operates on its String parameter

There's got to be a better way ...
 
John A Grandy said:
the conversion methods on the VB.NET String objects are of course
very useful ... but it would seem that one of the most common needs
is not properly addressed ...

if I do

Dim s As String
s = "I acTually Want the case To BE like THis"
TextBox1.Value = s.ToUpper()

My textbox does not have Value property, only a text property. Maybe you are
using web forms?
maybe I get what I want in that particular text-box .... but my
String object has lost its original case ...

Of course, I can do

Dim s As String
Dim s1 As String
s = "I acTually Want the case To BE like THis"
s1 = s
TextBox1.Value = s1.ToUpper()

but that's a couple extra lines of code.

StrConv() is no better because it also operates on its String
parameter

There's got to be a better way ...

I can not reproduce it. My original string stays unchanged.
 
* "John A Grandy said:
the conversion methods on the VB.NET String objects are of course very
useful ... but it would seem that one of the most common needs is not
properly addressed ...

if I do

Dim s As String
s = "I acTually Want the case To BE like THis"
TextBox1.Value = s.ToUpper()
'Value'?

maybe I get what I want in that particular text-box .... but my String
object has lost its original case ...

No, it hasn't.
Of course, I can do

Dim s As String
Dim s1 As String
s = "I acTually Want the case To BE like THis"
s1 = s
TextBox1.Value = s1.ToUpper()

but that's a couple extra lines of code.

StrConv() is no better because it also operates on its String parameter

Strings are immutable in .NET, modifying a string will create a new
string that replaces the old one (the old instance is destroyed).
Calling 'ToUpper' doesn't change the value of 's'.
 
Back
Top