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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PARSE

Status
Not open for further replies.

100dtl

Programmer
Aug 18, 2003
313
GB
Is it possble to get these values out of this text?

1351
1005
1130
1131
1052
I need to build a url but i'm not sure if how to get up to /

i know i can use # to find begining

1x #1351/3000000204 TEXT, 14 CM/N/A - Options: = £3.50 1x #1005/3000000859 TEXT/N/A - Options: = £14.50 1x #1130/3000003892 TEXT/N/A - Options: = £7.50 2x #1131/3000000095 TEXT, 7 CM/N/A - Options: = £9.00 1x #1052/3000000956 3" TEXT, 7 CM/N/A - Options: = £11.50
 
If you are looking to locate the position of a particular value in a string this will tell you it is in there:

Code:
text_string="1234567890"
text2find="4567"
If inStr(text_string,text2find) Then
' match found
End If

Actually, inStr() returns the starting point of the matching substring. So if you want to find a location in a string then try this:

Code:
If instr(text_string,text2find)=4 Then
' match found
End If

If you want the 2 characters of text immediately following, then this will do it:

Code:
next_2chars=mid(text_string),instr(text_string,text2find)+len(text2find),2)

Also, Regular Expressions can do it as well, but if you aren't familiar with their use, you ought to get a book on ASP and read up on what all it can do. Quite powerful and compact. It's quite similar to Regular Expressions in JavaScript or JScript, so it has some basic differences from the standard model for VBScript.
 
Just use regular expressions to grab out something from a text.
I used to think that reg expressions was something very tough and I was always using string suff like mid, left, len... etc to get rid of string problems until I found this : and this :
Just dare it !
 
I may add that once you have understood how to implement reg expression with vb script, the regular expression searched should be something like " #\d{4}/" and then use [regexp object].replace to only keep the 4 digits you want to extract (or just use the "replace" vb script function to get rid of non-digit characters) .

I guess it may seem a bit trivial when you read it but I swear you it is not so hard and later, you will write regular expressions even for fun :)
 
I agree with YannL on the pattern, but I believe you should actually use the .Execute method to get a collection of matches back, rather than the replace which would need a longer pattern to soak up the other parts of the string so that you could remove them.

-Tarwn

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
The never-completed website:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top