By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,030 Members | 1,323 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,030 IT Pros & Developers. It's quick & easy.

string manipulation

P: n/a
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
Share this Question
Share on Google+
11 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
Hi OHM,

2:18am as it says.

Why do you ask?

Regards,
Fergus
Nov 20 '05 #10

P: n/a
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

P: n/a
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.