472,122 Members | 1,576 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,122 software developers and data experts.

string manipulation

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))
Nov 20 '05 #1
11 2457
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
Nov 20 '05 #2
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

"John A Grandy" <jo*********@yahoo.com> wrote in message
news:eq*************@TK2MSFTNGP11.phx.gbl...
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))

Nov 20 '05 #3
Or

str = StrConv(str, vbProperCase)
Is easier ;-D

================================================== ===
"John A Grandy" <jo*********@yahoo.com> wrote in message
news:eq*************@TK2MSFTNGP11.phx.gbl...
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))

Nov 20 '05 #4
What time did you actually post this ?

"Fergus Cooney" <fi******@tesco.net> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
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

Nov 20 '05 #5
Cor
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
Nov 20 '05 #6
Sorry cor, what post of mine did u save ?

OHM

"Cor" <no*@non.com> wrote in message
news:3f***********************@reader20.wxs.nl...
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

Nov 20 '05 #7
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
Nov 20 '05 #8
Aha,

I see what you mean.
;-D
"Cor" <no*@non.com> wrote in message
news:3f*********************@reader22.wxs.nl...
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

Nov 20 '05 #9
Hi OHM,

2:18am as it says.

Why do you ask?

Regards,
Fergus
Nov 20 '05 #10
Even Borgs have to regenerate, you dont seem to sleep ever. Your post start
really early as well.
;-D

"Fergus Cooney" <fi******@tesco.net> wrote in message
news:ek**************@TK2MSFTNGP11.phx.gbl...
Hi OHM,

2:18am as it says.

Why do you ask?

Regards,
Fergus

Nov 20 '05 #11
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?
Nov 20 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

32 posts views Thread by tshad | last post: by
29 posts views Thread by zoro | last post: by
4 posts views Thread by WaterWalk | last post: by
10 posts views Thread by micklee74 | last post: by
3 posts views Thread by crprajan | last post: by
3 posts views Thread by frankeljw | last post: by
22 posts views Thread by mann_mathann | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.