Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 132,278 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,222 people online right now. Registration is fast and FREE... Join Now!




Can I Get a Response/Manipulating Strings/How to Pull the middle lette

 
Reply to this topicStart new topic

Can I Get a Response/Manipulating Strings/How to Pull the middle lette

powellm
post 30 Mar, 2008 - 01:35 PM
Post #1


New D.I.C Head

*
Joined: 30 Mar, 2008
Posts: 20

How do i pull the middle letter out of a phrase entered through a textbox

In the textbook that I am using they supply an algorithm to determine the position of the middle character of a string which is

vb

If Len(strQuote) Mod 2 <> 0 Then
intMiddleCharPos = Len(strQuote) \ 2 + 1
Else
intMiddleCharPos = Len(strQuote) \ 2
End If

my code look like this so far
Dim strQuote As String
Dim intMiddleCharPos As Integer

strQuote = txtQuote.Text
lblF.Caption = Left(strQuote, 1)
lblL.Caption = Right(strQuote, 1)
lblM.Caption = Mid


If Len(strQuote) Mod 2 <> 0 Then
intMiddleCharPos = Len(strQuote) \ 2 + 1
Else
intMiddleCharPos = Len(strQuote) \ 2
End If



For the lblM.caption to display the middle letter what to i enter to get it to display the middle letter of a phrase being entered into a textbox

This post has been edited by powellm: 30 Mar, 2008 - 02:37 PM
User is offlineProfile CardPM

Go to the top of the page

girasquid
post 31 Mar, 2008 - 10:42 AM
Post #2


Barbarbar

Group Icon
Joined: 3 Oct, 2006
Posts: 1,255



Thanked 14 times

Dream Kudos: 650
My Contributions


Try taking a look at String.Substring .
User is online!Profile CardPM

Go to the top of the page

born2c0de
post 1 Apr, 2008 - 04:41 AM
Post #3


printf("I'm a %XR",195936478);

Group Icon
Joined: 26 Nov, 2004
Posts: 3,905



Thanked 34 times

Dream Kudos: 2800

Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions


You can also use Mid(). Here's its syntax:
vb
Mid(source_string,position_to_extract_chars,number_of_chars_to_extract)


So, you could use it like this:
vb

Dim midletter as String
midletter = Mid(Txtquote.text,Len(txtquote.text)/2,1)
MsgBox(midletter & " is the middle letter")
User is offlineProfile CardPM

Go to the top of the page

powellm
post 3 Apr, 2008 - 02:56 PM
Post #4


New D.I.C Head

*
Joined: 30 Mar, 2008
Posts: 20

i figure it out thank you

Option Explicit

Private Sub cmData_Click()
Dim strQuote As String
Dim intMiddle As Integer

strQuote = txtQuote.Text
lblF.Caption = Left(strQuote, 1)
lblL.Caption = Right(strQuote, 1)

If Len(strQuote) Mod 2 <> 0 Then
intMiddle = Len(strQuote) \ 2 + 1
Else
intMiddle = Len(strQuote) \ 2
End If

lblM.Caption = Mid(strQuote, intMiddle, 1) 'Added this to make it Work'
End Sub

Private Sub cmdDone_Click()
Unload frmTextcase
End Sub

User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/22/08 12:42AM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month