Results 1 to 9 of 9

Thread: [RESOLVED] Get a string of unknown lenght ?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2006
    Posts
    612

    Resolved [RESOLVED] Get a string of unknown lenght ?

    I have a string similar in form to this “12345 RTYUICK 4566/45679/23456789/2344/677”

    But the real one will be different each time my runs, what I want to do is get the part of the string between the first two “/” do some calculations on it and put it back. Now in the example above “/45679/” the bit I need is the “45679” but in my app this could be “/1/” or up to “/100000000/”

    So I need to say something like goto the first “/” and grab all there is until the next “/”

    Is this possible? If so how?

  2. #2
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Get a string of unknown lenght ?

    Dim strRet() As String

    strRet = Split(your_string, "/")
    If Ubound(strRet) > 1 Then Debug.Print = strRet(1)

  3. #3
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Get a string of unknown lenght ?

    Another method
    Code:
    Private Sub Command1_Click()
     Dim sYourstring As String
     Dim nCutstr As String
     Dim stringtoappend As String
     Dim sFinalstr As String
     sYourstring = "12345 RTYUICK 4566/45679/23456789/2344/677"
     stringtoappend = "011111111"
     Dim ipos1 As Integer
      Dim ipos2 As Integer
      ipos1 = InStr(1, sYourstring, "/")
      ipos2 = InStr(ipos1 + 1, sYourstring, "/")
     nCutstr = Mid(sYourstring, ipos1 + 1, (ipos2 - ipos1) - 1)
     sFinalstr = Left(sYourstring, ipos1) & stringtoappend & Mid(sYourstring, ipos2, Len(sYourstring))
    End Sub
    Please mark you thread resolved using the Thread Tools as shown

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    May 2006
    Posts
    612

    Re: Get a string of unknown lenght ?

    Many thanks

  5. #5
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: [RESOLVED] Get a string of unknown lenght ?

    Addendum, to update then rebuild

    strRet(1) = new_string
    Debug.Print Join(strRet, "/")

  6. #6
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: [RESOLVED] Get a string of unknown lenght ?

    Nice method Leinard
    Please mark you thread resolved using the Thread Tools as shown

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    May 2006
    Posts
    612

    Re: [RESOLVED] Get a string of unknown lenght ?

    As ever my optimism and expectation that I could use this code exceeded my ability to adapt it for my use.

    This is the code I have used

    Code:
    Dim ipos1 As Integer
    Dim ipos2 As Integer
    Dim strBuffer1 As String
    Dim Cut As String
        ipos1 = InStr(1, strBuffer, "/")
        ipos2 = InStr(ipos1 + 1, strBuffer, "/")
        Cut = Mid(strBuffer, ipos1 + 1, (ipos2 - ipos1) - 1)
        strBuffer1 = CStr(CDbl(Cut) * 92314#)
        strBuffer = strBuffer & " Test Cal: " & strBuffer1
    Now it turns out that instead of the text between the first “/” and second “/” it turns out that I need the text between the third “/” and fourth “/” how do I adapt the code above to do this one, I have tried adding ipos3 and ipos4 and then changing the “Cut” statement but I cannot get it to work

  8. #8
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: [RESOLVED] Get a string of unknown lenght ?

    Use leinad31's code, then you just need strRet(3) (the 4th one, starting at 0). Just to be sure, you might also want to change If Ubound(strRet) > 1 to If Ubound(strRet) > 3
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  9. #9
    Lively Member
    Join Date
    Jun 2007
    Posts
    76

    Re: [RESOLVED] Get a string of unknown lenght ?

    y dont u just reference the value as an array like it setup?
    strRet(0), strRet(1)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width