Click here to Skip to main content
15,890,845 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using visual studio 2010 (vb.net- windows form ).

I have a text box which consist of number's date and string.
i need to highlight all numeric values and date in that text box and need an option to change the value on mouse click . (ie No changes in string content)

for example

let value in text box be

"Hi my name is Sidharth. I'm 26 yr old . my dob is 22/03/1990"

when value is loaded to text box
it should display as

"Hi my name is Sidharth. I'm 26 yr old . my dob is 22/03/1990"

on mouse click or mouse focus i need an option to change.

VB
Dim TextToFormat As Integer
       Dim TextFormat As String
       TextFormat = 1
       TextToFormat = "Hi my name is Sidharth. I'm 26 yr old . my dob is 22/03/1990"
       Dim count As New List(Of Integer)()
       For i As Integer = 0 To rText.Text.Length - 1
           If rText.Text.IndexOf(TextToFormat, i) <> -1 Then
               'If the word is found add the index to the list
               count.Add(rText.Text.IndexOf(TextToFormat, i))
           End If
       Next

       Try
           For i As Integer = 0 To count.Count - 1
               rText.[Select](count(i), TextToFormat.Length)
               Select Case TextFormat
                   Case 1
                       rText.SelectionFont = New Font(rText.Font.FontFamily, rText.Font.Size, FontStyle.Italic)

                   Case 2
                       rText.SelectionFont = New Font(rText.Font.FontFamily, rText.Font.Size, FontStyle.Italic)
               End Select
               count.RemoveAt(i)
           Next
       Catch
       End Try

in this im searching a text in txtbox and formatting the text
bt i need to get all numerical values.
Posted
Updated 22-May-14 20:04pm
v2
Comments
Karen Mitchelle 23-May-14 1:41am    
Code?
Sidharth R 23-May-14 1:47am    
yup that what i'm in search (vb.net)
Karen Mitchelle 23-May-14 1:51am    
You haven't started anything yet? Even a line of code for that? If you have, can you please provide some? Use the Improve question. Thanks.
Sidharth R 23-May-14 1:57am    
-- the content has been moved to the question --
Maciej Los

1 solution

The best way to achieve that is to use Regex[^] with pattern[^]: \d{1,} to find only numeric values.

Note: above pattern does not supports "/" and any other non-digits. You need to find pattern which meet your needs.
 
Share this answer
 
Comments
Karen Mitchelle 23-May-14 2:14am    
5ed.
You beat me to it. :)
Maciej Los 23-May-14 2:18am    
Thank you ;)

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