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

Get a specific letter from a word

P: n/a
How do you get a specific letter from a word?

For example, in English, I would say:

Get the fifth letter from the word "Computer"

Then the letter 'u' will be returned. (C-O-M-P-U-..., 'u' is the fifth letter)
How do you 'translate' this sentence into VB.net? Thanks!
--
Xero

http://www.chezjeff.net
My personal web portal
Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Use the Chars indexer property of the string:

Dim s As String = "Computer"
Console.WriteLine (s.Chars(4)) 'Index is zero based

HTH

"Xero" <jeff_@_chezjeff_._net(remove_underscores_and_this )> wrote in message
news:FC**********************************@microsof t.com...
How do you get a specific letter from a word?

For example, in English, I would say:

Get the fifth letter from the word "Computer"

Then the letter 'u' will be returned. (C-O-M-P-U-..., 'u' is the fifth
letter)
How do you 'translate' this sentence into VB.net? Thanks!
--
Xero

http://www.chezjeff.net
My personal web portal
Nov 21 '05 #2

P: n/a
Hi Jeff

this is one possible way

Dim strWoord As String = "COMPUTER"
Dim strLetter As String
Dim intLetter As Integer
strLetter = InputBox("Give the ... letter")
If strLetter.Length > 0 AndAlso IsNumeric(strLetter) Then
intLetter = CInt(strLetter)
If intLetter > strWoord.Length Then
MsgBox("The word isn't this long")
Else
MsgBox("The letter is " & Mid(strWoord, intLetter, 1))
End If
End If

hth

"Xero" <jeff_@_chezjeff_._net(remove_underscores_and_this )> wrote in message
news:FC**********************************@microsof t.com...
How do you get a specific letter from a word?

For example, in English, I would say:

Get the fifth letter from the word "Computer"

Then the letter 'u' will be returned. (C-O-M-P-U-..., 'u' is the fifth letter) How do you 'translate' this sentence into VB.net? Thanks!
--
Xero

http://www.chezjeff.net
My personal web portal

Nov 21 '05 #3

P: n/a
Nice! I've been using Mid() but that looks better.

Matthew

"Shiva" <sh******@online.excite.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Use the Chars indexer property of the string:

Dim s As String = "Computer"
Console.WriteLine (s.Chars(4)) 'Index is zero based

HTH

"Xero" <jeff_@_chezjeff_._net(remove_underscores_and_this )> wrote in
message
news:FC**********************************@microsof t.com...
How do you get a specific letter from a word?

For example, in English, I would say:

Get the fifth letter from the word "Computer"

Then the letter 'u' will be returned. (C-O-M-P-U-..., 'u' is the fifth
letter)
How do you 'translate' this sentence into VB.net? Thanks!
--
Xero

http://www.chezjeff.net
My personal web portal

Nov 21 '05 #4

P: n/a
Xero schrieb:
How do you get a specific letter from a word?

For example, in English, I would say:

Get the fifth letter from the word "Computer"

Then the letter 'u' will be returned. (C-O-M-P-U-..., 'u' is the fifth letter)
How do you 'translate' this sentence into VB.net? Thanks!


Take a look at the documentation:

'GetChar' gets a single character from a string. 'Mid' can be used to
get more than one character.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #5

P: n/a
Jeff,

I miss the one I use

dim MyFiftLetter as String = "Computer".substring(4,1)

I hope this makes it more complete

Cor

"Xero" <jeff_@_chezjeff_._net(remove_underscores_and_this )>
How do you get a specific letter from a word?

For example, in English, I would say:

Get the fifth letter from the word "Computer"

Then the letter 'u' will be returned. (C-O-M-P-U-..., 'u' is the fifth
letter)
How do you 'translate' this sentence into VB.net? Thanks!
--
Xero

http://www.chezjeff.net
My personal web portal

Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.