Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I delete characters in a string? 1

Status
Not open for further replies.

lhailey

Programmer
Sep 24, 2010
4
US
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
 


Hi,

This is a VBA forum and not VB Script, which is forum329.
I want my code to output: "3900".
That being said, is the form of this string ALWAYS...
[tt]
"trash;NEED;trash;trash;trash"
[/tt]
If so...
Code:
MyValue = Split(YourString, ";")(1)


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Thanks Skip, I learned something about Split. I did not know you could do get an array item directly like that.
Code:
Dim MyString As String

MyString = "trash;NEED;trash;trash;trash"
MsgBox Split(MyString, ";")(1)
displays "NEED"

That is not menioned in Help. That can be very handy. Have been building the array, THEN getting the item value as a separate instruction. Saves me a step.


unknown
 
Not that you need one, as you are as rich as Croesus with stars, but the principle remains the same. Appreciation for something I can use. Have un autre.


unknown
 


Thanx, Gerry! You made me remember The Singing Cowboy.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
So hum me a few bars so I can figure out which singing cowboy.

Gene?
Roy?


unknown
 



Your REPLY sparked my memory.

If you need a peek...
Back in the Saddle Again

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Well, if the cattle are feeding on Datura stramonium, then are going to bombed out of their gourds (if cows HAVE gourds), and you will probably need your 'ol .44.


unknown
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top