GlobaLevel
asked on
vbscript - instrRev reduce a string down
does anyone know how to reduce a string down with the instrRev or instr..dynamically...
Logical5=6015\:USD\:5\:605 0@5@6017@6 025@5@0@0\ :0\:0\:0@f alse@-1_1@ 44@0@0@-1_ 1;5;x;0\:0 \:0\:0;0;0
var1 = @5@6017@6025@5@0@0\:0\:0\: 0@false@-1 _1@44@0@0@ -1_1;5;
var2 = ;0\:0\:0\:0;0;0
so that I can now modify the x value in that row...
newRowVar = "Logical5=6015\:USD\:5\:60 50" & var1 & "900" & var2
thanks!!
Logical5=6015\:USD\:5\:605
var1 = @5@6017@6025@5@0@0\:0\:0\:
var2 = ;0\:0\:0\:0;0;0
so that I can now modify the x value in that row...
newRowVar = "Logical5=6015\:USD\:5\:60
thanks!!
ASKER
hi angelIII...sorry x is not a real value I only put that in there so you can see where the value is located...its a number that change ...just like any other value in this row...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I know ...thats what im asking.. ;)
var1 = Mid(origVar, InStrRev(origVar, "=") +1)
msgbox(var1)
var2 = right(var1, InStrRev(var1, "\") +1)
msgbox(var2)
var3 = right(var2, InStrRev(var2, "\") +1)
msgbox(var3)
var4 = right(var3, InStrRev(var3, "\") +1)
msgbox(var4)
var5 = (left(right(var4, InStrRev(var4, "@") +1)-1))
msgbox(var5)
var1 = Mid(origVar, InStrRev(origVar, "=") +1)
msgbox(var1)
var2 = right(var1, InStrRev(var1, "\") +1)
msgbox(var2)
var3 = right(var2, InStrRev(var2, "\") +1)
msgbox(var3)
var4 = right(var3, InStrRev(var3, "\") +1)
msgbox(var4)
var5 = (left(right(var4, InStrRev(var4, "@") +1)-1))
msgbox(var5)
you might want to check split() function, but still not sure how you locate this exactly?
Something like this might work. It's reasonably long winded, as opposed to using Split, but does the job. It also works on the assumption that there is exactly the same amount of semi-colons in each line.
Regards,
Rob.
Regards,
Rob.
strLine = "Logical5=6015\:USD\:5\:6050@5@6017@6025@5@0@0\:0\:0\:0@false@-1_1@44@0@0@-1_1;5;x;0\:0\:0\:0;0;0"
var1 = ""
var2 = ""
strValue = ""
' Find the first ;
intPos = InStr(strLine, ";")
If intPos > 0 And intPos < Len(strLine) Then
' Find the second ;
intPos = InStr(intPos + 1, strLine, ";")
var1 = Left(strLine, intPos)
If intPos > 0 And intPos < Len(strLine) Then
' Now find the next ; and get the value of x in between
intPos2 = InStr(intPos + 1, strLine, ";")
If intPos2 > 0 Then
strValue = Mid(strLine, intPos + 1, (intPos2 - 1) - intPos)
var2 = Mid(strLine, intPos2)
End If
End If
End If
MsgBox "var1: " & var1 & VbCrLf & "var2: " & var2 & VbCrLf & "strValue: " & strValue
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
turns out the '6050' is an unknown value and needs to stay dynamic...
was this:
newRowVar = "Logical5=6015\:USD\:5\:60 50" & var1 & "900" & var2
needs to be this:
newRowVar = "Logical5=6015\:USD\:5\:" & var1 & "900" & var2
was this:
newRowVar = "Logical5=6015\:USD\:5\:60
needs to be this:
newRowVar = "Logical5=6015\:USD\:5\:" & var1 & "900" & var2
OK, what about this?
Regards,
Rob.
Regards,
Rob.
strLine = "Logical5=6015\:USD\:5\:6050@5@6017@6025@5@0@0\:0\:0\:0@false@-1_1@44@0@0@-1_1;5;x;0\:0\:0\:0;0;0"
var1 = ""
var2 = ""
var3 = ""
strValue2 = ""
arrBits = Split(strLine, ";")
For intBit = 0 To 1
var1 = var1 & arrBits(intBit) & ";"
Next
strValue2 = arrBits(2)
For intBit = 3 To 5
var3 = var3 & ";" & arrBits(intBit)
Next
' Now find the first @ in var1
intEnd = InStr(var1, "@")
intStart = InStrRev(var1, ":", intEnd)
strValue1 = Mid(var1, intStart + 1, intEnd - 1 - intStart)
var2 = Mid(var1, intEnd)
var1 = Left(var1, intStart)
strNewRow = var1 & strValue1 & var2 & strValue2 & var3
MsgBox "var1: " & var1 & VbCrLf & "strValue1: " & strValue1 & VbCrLf & "var2: " & var2 & VbCrLf & "strValue2: " & strValue2 & VbCrLf & "var3: " & var3 & VbCrLf & VbCrLf & "strNewRow: " & VbCrLf & strNewRow
Maybe it's better to do this with regular expressions.
You can use http://www.txt2re.com to create the regex to select x and the replace method to replace x with the new value. Select VBScript at the bottom to get the code generated.
replace method: http://msdn.microsoft.com/en-us/library/k9z80300(VS.85).aspx
You can use http://www.txt2re.com to create the regex to select x and the replace method to replace x with the new value. Select VBScript at the bottom to get the code generated.
replace method: http://msdn.microsoft.com/en-us/library/k9z80300(VS.85).aspx
ASKER
tv0085...can you give feedback as to what this regular expression generator actually does..thanks...
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
if yes, you might consider doing a
newRowVar = REPLACE(Logical5, ";x;", "900")
apart from that, it's far from obvious otherwise how to "locate" the x...
you might want to clarify the "rule(s)" ?