954,557 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Remove sections from a string and then append together to form another

{"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

bob12321
Newbie Poster
4 posts since Aug 2011
Reputation Points: 10
Solved Threads: 0
 
adam_k
Practically a Posting Shark
803 posts since Jun 2011
Reputation Points: 256
Solved Threads: 149
 

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
GeekByChoiCe
Master Poster
721 posts since Jun 2009
Reputation Points: 208
Solved Threads: 168
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: