Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello

I need to get the cursor word that surrounds a cursor when a text-box with text ix clicked

so if for example i have
Hell|o
, then i need to get the word hello. Here the Pipe has been used to represent the cursor

thanks
Posted
Updated 11-Dec-11 10:16am

1 solution

thanks, but i found a simpler solution
VB
Dim intCursor As Integer = txtInput.SelectionStart
            Dim intStart As Int32 = CInt(IIf(intCursor - 1 < 0, 0, intCursor - 1))
            Dim intStop As Int32 = intCursor
            intStop = txtInput.Text.IndexOf(SingleSpace, intCursor)
            intStart = txtInput.Text.LastIndexOf(SingleSpace, intCursor)
            If intStop < 0 Then
                intStop = txtInput.Text.Length
            End If
            If intStart < 0 Then
                intStart = 0
            End If
            debug.print( txtInput.Text.Substring(intStart, intStop - intStart).Trim)
 
Share this answer
 
Comments
[no name] 12-Dec-11 6:37am    
Which probably will not work how you expect. Try e.g. a text "like,this". But anyway, make it complete is a good exercise to get some “Parsing” experience.
Cool Smith 12-Dec-11 10:01am    
i have fixed that, but still without looping
[no name] 12-Dec-11 17:59pm    
That's fine, but to be exact you let loop and made some || I think :) Anyway, essential is you solved your problem.

So the only thing to do is accept your solution as "the solution" to mark the question as solved.

Regards

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900