Can you help? I am using vbscript with QTP and I am trying to delete characters in a string. I want my code to output: "3900".
The original string is: "System;3900;Chassis 1;S-Blade;3900 01.01.01"
My code currently outputs: "3900 Remove from Here to End 1;S-Blade;3900 01.01.01"
How do I modify my code below to output "3900" only?
-----------------------------------------------------
'give me the 4th row of runtime dt
port1 = DataTable.GetSheet("NewGetRequest").GetParameter("Get").ValueByRow(4)
print "Port 1 Row is: " & port1
'give me the last 8 characters
p1suffix = Right(port1, 8)
print "Port 1 suffix is: " & p1suffix
'give me the position of text "System;;" Compare:"System;3900;Chassis 1;S-Blade;3900 01.01.01"
'this string is 25 characters from beginning to the ";" in "System;"
p1mypos = InStr (1, port1, "System;;", vbTextCompare)
print "Port 1 text position is " & p1mypos
'copy mypos to dt
datatable("Position", dtLocalSheet) = p1mypos
'add mypos + 7 characters
p1addchr = p1mypos + 8
print "New Port 1 text position is: " & p1addchr
'copy p1adcchr to dt
datatable("Add", dtLocalSheet) = p1addchr
'do mid function from p1addchr
p1 = Mid(port1, p1addchr) ' MyVar contains "Script".
print "New port 1 suffix is: " & p1
'new port 1 suffix is:
'3900;Chassis 1;S-Blade;3900 01.01.01
Function ReplaceTest(patrn, replStr)
' Dim regEx, str1
'str1 = "The quick brown fox jumps over the lazy dog."
' Create regular expression.
Set regEx = New RegExp
regEx.Pattern = patrn
regEx.IgnoreCase = True
' Make replacement.
ReplaceTest = regEx.Replace(p1, replStr)
End Function
print (ReplaceTest(";Chassis", " Remove from Here to End")) ' Replace 'fox' with 'cat'.3900 Remove from Here to End 1;S-Blade;3900 01.01.01
The original string is: "System;3900;Chassis 1;S-Blade;3900 01.01.01"
My code currently outputs: "3900 Remove from Here to End 1;S-Blade;3900 01.01.01"
How do I modify my code below to output "3900" only?
-----------------------------------------------------
'give me the 4th row of runtime dt
port1 = DataTable.GetSheet("NewGetRequest").GetParameter("Get").ValueByRow(4)
print "Port 1 Row is: " & port1
'give me the last 8 characters
p1suffix = Right(port1, 8)
print "Port 1 suffix is: " & p1suffix
'give me the position of text "System;;" Compare:"System;3900;Chassis 1;S-Blade;3900 01.01.01"
'this string is 25 characters from beginning to the ";" in "System;"
p1mypos = InStr (1, port1, "System;;", vbTextCompare)
print "Port 1 text position is " & p1mypos
'copy mypos to dt
datatable("Position", dtLocalSheet) = p1mypos
'add mypos + 7 characters
p1addchr = p1mypos + 8
print "New Port 1 text position is: " & p1addchr
'copy p1adcchr to dt
datatable("Add", dtLocalSheet) = p1addchr
'do mid function from p1addchr
p1 = Mid(port1, p1addchr) ' MyVar contains "Script".
print "New port 1 suffix is: " & p1
'new port 1 suffix is:
'3900;Chassis 1;S-Blade;3900 01.01.01
Function ReplaceTest(patrn, replStr)
' Dim regEx, str1
'str1 = "The quick brown fox jumps over the lazy dog."
' Create regular expression.
Set regEx = New RegExp
regEx.Pattern = patrn
regEx.IgnoreCase = True
' Make replacement.
ReplaceTest = regEx.Replace(p1, replStr)
End Function
print (ReplaceTest(";Chassis", " Remove from Here to End")) ' Replace 'fox' with 'cat'.3900 Remove from Here to End 1;S-Blade;3900 01.01.01