Get a specific letter from a word

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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!
 
Use the Chars indexer property of the string:

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

HTH

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!
 
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 said:
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.
 
Jeff,

I miss the one I use

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

I hope this makes it more complete

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top