Hack Forums
[.NET] Source - Retrieve the title of a site and add it plus the link to a ListView. & More - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] Source - Retrieve the title of a site and add it plus the link to a ListView. & More (/showthread.php?tid=2919915)

Pages: Pages 1 2


Source - Retrieve the title of a site and add it plus the link to a ListView. & More - SomeWhiteGuy - Oct 15, 2012

Simple as fuck, I know. I made it as an example for some kid. It's a "Site Manager".

Gif:
Spoiler (Click to View)

DL: http://www.coding-forums.com/hf/sources/download.php?id=4

I also made this as an example and it's in the same project, what I've started to do is just add everything to one huge ass project called "Examples". Right now there are only 2 things that work (out of 3).

Gif:
Spoiler (Click to View)



Thanks for any interest and I hope someone learns something! 🙂


* - ๖ۣۜMephobia - Oct 15, 2012

Some l33t coding you got there... Get back on Auxilium SWG... Anyways, nice share.


* - Plump - Oct 15, 2012

What do you use to record the gifs?


* - SomeWhiteGuy - Oct 15, 2012

(Oct 15, 2012 08:23 PM)Plump Wrote:  What do you use to record the gifs?

I use Camtasia Studio to record the GIF's, and also any videos that I happen to upload to YouTube.


* - Plump - Oct 15, 2012

I see, thanks a lot sir. :D
Nice share btw.


* - Banksу - Oct 15, 2012

I don't really know much about RegEx, but from what I got from that expression was that it gets anything that is A-z & 0-9 between the title tags.

What happens if someone uses a character like '-' or '&'?


* - Dark Molecule - Oct 15, 2012

Nice source, I can think of a project or two i have sitting around I could mod this for. Thanks for sharing :]


* - SomeWhiteGuy - Oct 15, 2012

(Oct 15, 2012 08:35 PM)Banksу Wrote:  I don't really know much about RegEx, but from what I got from that expression was that it gets anything that is A-z & 0-9 between the title tags.

What happens if someone uses a character like '-' or '&'?

You are correct, and I didn't really think about that.

Easy work-around:
Code
(?<=\<title\>)[a-zA-Z0-9-&\|\s]*(?=\</title\>)



* - Banksу - Oct 15, 2012

(Oct 15, 2012 08:42 PM)SomeWhiteGuy Wrote:  You are correct, and I didn't really think about that.

Easy work-around:
Code
(?<=\<title\>)[a-zA-Z0-9-&\|\s]*(?=\</title\>)

Or you could do how I would have done it:

Code
siteTitle = GetBetween(siteSource, "<title>", "</title>", 0)

Private String GetBetween(ByVal source As String, ByVal str1 As String, ByVal str2 As String, ByVal index As Integer)
Dim tmp As String = Split(source, str1)(index + 1)
Return Split(tmp, str2)(index)
End Function

That way it returns any string no matter what is in it. 😉


* - SomeWhiteGuy - Oct 15, 2012

(Oct 15, 2012 09:13 PM)Banksу Wrote:  Or you could do how I would have done it:

Code
siteTitle = GetBetween(siteSource, "<title>", "</title>", 0)

Private String GetBetween(ByVal source As String, ByVal str1 As String, ByVal str2 As String, ByVal index As Integer)
Dim tmp As String = Split(source, str1)(index + 1)
Return Split(tmp, str2)(index)
End Function

That way it returns any string no matter what is in it. 😉

That works too. Thanks for the function! 🙂


* - marvinn - Oct 16, 2012

I would have used <title>(.*)</title> that will match anything and since there is only one title tag its asll good :)


* - -SiR- - Oct 16, 2012

or you try this (?<=\<title\>)(.*)(?=\</title\>)


* - SomeWhiteGuy - Oct 16, 2012

Thanks everyone for the compliments and improved RegEx patterns.


* - soft2050 - Oct 16, 2012

(Oct 16, 2012 06:07 AM)-SiR- Wrote:  or you try this (?<=\<title\>)(.*)(?=\</title\>)
Exactly, with making the match non-greedy and no reason to capture that title: (?<=\<title\>).*?(?=\</title\>)

Also, no need of using a loop:
[img]http://rapidimg.org/server/files/507dcedc9551dVGy9IO.png[/img]

siteTitle = regex.Match(siteSource).Value will work good which will return first matched value.


* - SomeWhiteGuy - Oct 16, 2012

(Oct 16, 2012 08:48 AM)soft2050 Wrote:  Exactly, with making the match non-greedy and no reason to capture that title: (?<=\<title\>).*?(?=\</title\>)

Also, no need of using a loop:
[img]http://rapidimg.org/server/files/507dcedc9551dVGy9IO.png[/img]

siteTitle = regex.Match(siteSource).Value will work good which will return first matched value.

You are correct. Considering there will only be one match. I'm just so used to doing that, lol. o_o