{"status":"OK","data":[{"service":"hotfile","sid":"alcva","filename":"Cash.2008.x264.utkuemre.part1.rar"},

I need to convert the string above into - bearing in mind the string is not constant
http://rapidgen.net/"SID VALUE"/"FILENAME"

So in this example it would be
http://rapidgen.net/alcva/Cash.2008.x264.utkuemre.part1.rar

What is the code that will extract only these pieces of this information?

THANKS

Recommended Answers

All 2 Replies

I dont think String manipulation is the way to go here.
Also the example string of the poster is not very well formed.

But here is a working example:

Sub Main()

		Dim testString() As String = {"{""status"":""OK"",""data"":[",
		   "{""service"":""hotfile"",""sid"":""alcva"",""filename"":""Cash.2008.x264.utkuemre.part1.rar""},",
		   "{""service"":""hotfile"",""sid"":""AApCR"",""filename"":""Cash.2008.x264.utkuemre.part2.rar""},",
		   "{""service"":""hotfile"",""sid"":""SG6E1"",""filename"":""Cash.2008.x264.utkuemre.part3.rar""},",
		   "{""service"":""hotfile"",""sid"":""hu4Ue"",""filename"":""Cash.2008.x264.utkuemre.part4.rar""}",
		   "]}"}
		Dim finalString As String = String.Join(vbNewLine, testString)
		Dim regEx As New Text.RegularExpressions.Regex("service"":""hotfile"",""sid"":""(?<sid>.*)"",""filename"":(?<file>"".*"")", Text.RegularExpressions.RegexOptions.Multiline)
		For Each _match As System.Text.RegularExpressions.Match In regEx.Matches(finalString)
			Console.WriteLine(String.Format("http://rapidgen.net/{0}/{1}", _match.Groups("sid").Value, _match.Groups("file").Value.Trim(Chr(34))))
		Next
		Console.Read()

	End Sub

Above code prints the following lines:

http://rapidgen.net/alcva/Cash.2008.x264.utkuemre.part1.rar
http://rapidgen.net/AApCR/Cash.2008.x264.utkuemre.part2.rar
http://rapidgen.net/SG6E1/Cash.2008.x264.utkuemre.part3.rar
http://rapidgen.net/hu4Ue/Cash.2008.x264.utkuemre.part4.rar
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.