Gettign part of a string.

jorge

Well-known member
Joined
Jul 13, 2003
Messages
239
Location
Belgium
ok my application get a string passed to is, but i only need a small part of it so how do i get it?
GET /index.htm HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
Accept-Language: en-us
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)
Host: schrauwen.no-ip.org:81
Connection: Keep-Alive
Cookie: useralb=Friends%2FSofie; isadmin=1; member_id=1; pass_hash=fc86d40ab841bf68d020223175187e65
I would like to get some information from that like:
the filename and path after GET,
User-Agent, and Cookies
 
Last edited by a moderator:
Regular Expressions are really powerful for identifying areas in strings. Heres a simple example:

Code:
Dim s As String = tvwBillOfMaterial.SelectedNode.Text
Dim re As New System.Text.RegularExpressions.Regex("\(\d+\.?\d?\d?\d?\d?")  finds the quantity from the nodes description string
Dim m As System.Text.RegularExpressions.Match = re.Match(s)
Quantity_From_Node_Description = m.ToString
Hope it helps
 
There are various was to go about this depending on the rigidity of the string.

There are two useful functions here; myString.SubString and myString.IndexOf. The former returns part of the string, where you specify the first character to get, and optionally how many characters from that point to get. IndexOf returns the first index of a specific character or string.

So, for example, you could Get the first index of "GET", the first index of HTTP, and get the characters between that.

edit: or you could use regex :P
 
Back
Top