string manipulation

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

John A Grandy

what is wrong with this ? (assuming s is > 1 char long)

Dim s As String

s = s.ToUpper(s.Substring(1, 1)) & s.ToLower(s.Substring(2))
 
Hi John,

Here's a .NET gotcha. A String, like an array, like practically everything
now, starts counting from 0.

s.Substring (1, 1) is the 2nd character
s.Substring (2) is the 3rd character onwards.

Also the Mid Left and Right functions from VB6 are very forgiving
(sensibly and usefully so) but the String class functions are not. Go out of
range with these and it's Exception time.

You can still use Mid if you wish.

Regards,
Fergus
 
John,
In addition to Fergus's comments.

String.ToUpper does not accept a string as a parameter. It operators on the
current instance of the string. So if you want the upper case the first
character of "s" you would use:

s = s.SubString(0, 1).ToUpper()

As Fergus pointed out the index is zero based, so to get the first character
of "s" you pass 0, then you upper case the result of the sub string.

Of course you could have upper cased the entire string then took the sub
string of that.

s = s.ToUpper().SubString(0, 1)

Hope this helps
Jay
 
Or

str = StrConv(str, vbProperCase)


Is easier ;-D

=====================================================
 
Hi OMH,
I found this funny, I thought what was it, I was searching on OHM and then I
saw you did post it again.
Now I have saved it..
Cor
 
Hi OHM
That string conversion, you had a long discussion with Herfried about that a
while ago, and I was laughing about it.
So I thought that I d'nt forget.
(You won the discussion )
I thought I d'nt know if you where in this newsgroup today, so I started
searching for it, because I thougth that is the answer.
Could not find it in MSDN and started to search for your messages, then I
saw you had answered it.

So now I have saved your solution in a seperate map.

:-)

Cor
 
Even Borgs have to regenerate, you dont seem to sleep ever. Your post start
really early as well.


;-D
 
Morning OHM,

ROFL. That's a good 'un. Borg's ain't got a patch on me. Hmm, perhaps
patch is the wrong word there.

One theory is that I'm actually asleep right now and this is my astral
body using telekenesis to type.

;-)

Regards,
Fergus

ps. Did you see my response to your Troll comment?
 
Back
Top