[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?
Re: Get a string of unknown lenght ?
Dim strRet() As String
strRet = Split(your_string, "/")
If Ubound(strRet) > 1 Then Debug.Print = strRet(1)
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
Re: Get a string of unknown lenght ?
Re: [RESOLVED] Get a string of unknown lenght ?
Addendum, to update then rebuild
strRet(1) = new_string
Debug.Print Join(strRet, "/")
Re: [RESOLVED] Get a string of unknown lenght ?
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 :confused: :eek2: :confused:
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
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)