Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Numbers with in a String

drkajundrkajun Posts: 2Member
Hay Guys,
I need help with something. I need to find a number with in a string. Now this number may be double digits and changes all the time. I want to extract the number from the string.

Any Ideas?


Thanks,
DrKajun

Comments

  • infidelinfidel Posts: 2,900Member
    : Hay Guys,
    : I need help with something. I need to find a number with in a string. Now this number may be double digits and changes all the time. I want to extract the number from the string.
    :
    : Any Ideas?

    You'll have to be more specific. Is it the only thing in the string? What is the range of possible values? What other "noise" characters might be there?


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]

  • Ase_CooperAse_Cooper Posts: 5Member
    : Hay Guys,
    : I need help with something. I need to find a number with in a string. Now this number may be double digits and changes all the time. I want to extract the number from the string.
    :
    : Any Ideas?
    :
    :
    : Thanks,
    : DrKajun
    :
    :

    Well, my best guess, what what you've given me (and assuming some other things) is that you want to use a variable that counts whats happening. For this example, use "c" as your counter variable. Make the changing variable add whatever to it (eg. c = c + 1) and declare it Globally. Now, finding the number within the string is the easy part. Simply do something like this:

    [code] Public somethingrather (1 to c) As String [/code]

    c is the always changing variable. As long as its decalred Globally in a module (Project, Add Module Command) you should have no problem. I hope I helped.

  • pseudocoderpseudocoder Posts: 682Member ✭✭✭
    : Hay Guys,
    : I need help with something. I need to find a number with in a string. Now this number may be double digits and changes all the time. I want to extract the number from the string.
    :
    : Any Ideas?
    :
    :
    : Thanks,
    : DrKajun

    I'm not that familiar with VB, but couldn't you loop through the string using the mid function, and apply isnumeric along the way?

    [code]
    for i=1 to len(string)
    if isnumeric(mid(string, i, 1)) then
    ' keep track of current pos
    ' loop through while there's a number

    cpos = i
    epos = cpos

    while isnumeric(mid(string, epos, 1))
    epos = epos + 1
    wend

    nstr = mid(string, spos, epos - spos)

    ' nstr has a number of n consecutive values if they exist
    exit for
    end if
    next[/code]

  • MicroDotMicroDot Posts: 142Member
    [b][red]This message was edited by MicroDot at 2004-12-21 10:5:35[/red][/b][hr]
    : Hay Guys,
    : I need help with something. I need to find a number with in a string. Now this number may be double digits and changes all the time. I want to extract the number from the string.
    :
    : Any Ideas?
    :
    :
    : Thanks,
    : DrKajun
    :
    :

    Hi,
    Try something like this:

    [code]

    Private Function ExtNum(ByVal strValue As String) As Integer
    Dim strNum As String
    Dim i As Integer

    On Error Resume Next

    For i = 1 To Len(strValue)
    If IsNumeric(Mid(strValue, i, 1)) Then strNum = strNum & Mid(strValue, i, 1)
    Next i

    ExtNum = CInt(strNum)
    End Function

    [/code]

    [hr]

    [b][blue]//MicroDot[/blue][/b]



  • Muneeb ShakoorMuneeb Shakoor Posts: 4Member
    : : Hay Guys,
    : : I need help with something. I need to find a number with in a string. Now this number may be double digits and changes all the time. I want to extract the number from the string.
    : :
    : : Any Ideas?
    :
    : You'll have to be more specific. Is it the only thing in the string? What is the range of possible values? What other "noise" characters might be there?
    :
    :
    : [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]
    :
    : [code]
    : $ select * from users where clue > 0
    : no rows returned
    : [/code]
    :
    :


    You can do this if you have good programming logics because there are some problems which can only be solved by pure programming. The solution immediately comes in my mind is:

    [code]
    dim i as integer
    dim str as string
    dim formednumber as long
    dim tempstr as string

    str = txtstring.text

    for i = 1 to len(str)
    if isNumeric(mid$(str,i,1)) then tempstr = tempstr & mid$(str,i,1)
    next

    formednumber = clng(tempstr)
    [/code]
  • Muneeb ShakoorMuneeb Shakoor Posts: 4Member
    : : Hay Guys,
    : : I need help with something. I need to find a number with in a string. Now this number may be double digits and changes all the time. I want to extract the number from the string.
    : :
    : : Any Ideas?
    :
    : You'll have to be more specific. Is it the only thing in the string? What is the range of possible values? What other "noise" characters might be there?
    :
    :
    : [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]
    :
    : [code]
    : $ select * from users where clue > 0
    : no rows returned
    : [/code]
    :
    :


    You can do this if you have good programming logics because there are some problems which can only be solved by pure programming. The solution immediately comes in my mind is:

    [code]
    dim i as integer
    dim str as string
    dim formednumber as long
    dim tempstr as string

    str = txtstring.text

    for i = 1 to len(str)
    if isNumeric(mid$(str,i,1)) then tempstr = tempstr & mid$(str,i,1)
    next

    formednumber = clng(tempstr)
    [/code]


  • drkajundrkajun Posts: 2Member
    : : Hay Guys,
    : : I need help with something. I need to find a number with in a string. Now this number may be double digits and changes all the time. I want to extract the number from the string.
    : :
    : : Any Ideas?
    : :
    : :
    : : Thanks,
    : : DrKajun
    : :
    : :
    :
    : Hi,
    : Try something like this:
    :
    : [code]
    :
    : Private Function ExtNum(ByVal strValue As String) As Integer
    : Dim strNum As Integer
    : Dim i As Integer
    :
    : On Error Resume Next
    :
    : For i = 1 To Len(strValue)
    : If IsNumeric(Mid(strValue, i, 1)) Then strNum = strNum & Mid(strValue, i, 1)
    : Next i
    :
    : ExtNum = CInt(strNum)
    : End Function
    :
    : [/code]
    :
    : [hr]
    :
    : [b][blue]//MicroDot[/blue][/b]
    :
    :

    Sorry for being so veag, I know what I want to do but it's hard to explain.

    MicroDot, I think you may have give'in me a way to pull off my task. The "IsNumeric" function may allow me to put to geather some logic to find the number with in my string. Learn somthing new everyday.

    THANKS GUYS! I'll keep you posted.

    [b][red]DrKajun[/red][/b]
Sign In or Register to comment.