Click here to Skip to main content
15,890,609 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to edit numerical values in a paragraph without editing any character content??

i'm using vb form and mssql database

i have a paragraph content including some numeric values date and character.

i need to take the entire string and need to edit the numeric numbers in the string via vb form and save back to database with out any changes in characters..

[ Note : - Eg: let input string be " ON 25/03/2014 u need to pay Rs 2000." The output after editing will be " ON 17/12/2014 u need to pay Rs 20." The above is just an example . The string is a paragraph not just a sentence

]
Posted
Comments
[no name] 23-May-14 5:41am    
Try to extract the numeric values through code and save their position in the string to an array. After editing replace the numbers.

For Example,
" ON 25/03/2014 u need to pay Rs 2000."
Try to extract 25, 03, 2014 and 2000. And then save their position. Ex., the position of 25 is 3 and so on.
Sidharth R 23-May-14 5:53am    
can u get me a sample code for That ?
Even i'm also trying for same

1 solution

I wrote the code for only extracting the numbers.
VB
 Public Class Number
   Public Value As Integer, Position As Integer
   Public Sub New(v As Integer, p As Integer)
         Value = v
         Position = p
   End Sub
 End Class
 Public Shared Function ExtractNumbers(str As String) As List(Of Number)
        Dim r As New List(Of Number)()
        Dim l As Integer = str.Length
        Dim i As Integer = 0
        Dim tmp As String = ""
        Dim t As Integer
        For i = 0 To l - 1
           If Char.IsDigit(str(i)) Then
               t = i
               tmp = ""
               tmp = tmp & str(i)
               i += 1
             While Char.IsDigit(str(i))
                 tmp = tmp & str(i)
                 i += 1
             End While
             r.Add(New Number(Integer.Parse(tmp), t))
         End If
     Next
     Return r
End Function

I wrote this code myself. The function ExtractNumbers returns a list of Number. The Number class has two variables Value and Position. Value is the value of the number. Position is the position of the number in the list. Use it like this:
VB
Dim a As String = "ON 25/03/2014 u need to pay Rs 2000."
Dim ln As List(Of Number) = ExtractNumbers(a)
 
Share this answer
 
Comments
Sidharth R 26-May-14 1:55am    
after that how to enable edit option for numerical value in a string ?

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