Problem Getting Strings

  • (2 Pages)
  • +
  • 1
  • 2

20 Replies - 604 Views - Last Post: 14 February 2013 - 05:44 PM Rate Topic: -----

#1 LilGhost  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 98
  • Joined: 12-October 12

Problem Getting Strings

Posted 14 February 2013 - 02:45 PM

Hey, so i'm working on a little program where you copy and paste the source of another program and it takes all the strings from the program and then appends them to a textbox.

Here was my original code:
Dim r As New Regex(""".*""")
Dim sS As MatchCollection = r.Matches(textbox1.text)
For Each s As Match In sS
Textbox2.text &= s.Value
Next



Issue is that i need it to not only work with quotes inside of a string (double quotes) and it keeps on missing strings.

This post has been edited by LilGhost: 14 February 2013 - 03:03 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Problem Getting Strings

#2 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1053
  • View blog
  • Posts: 4,080
  • Joined: 02-July 08

Re: Problem Getting Strings

Posted 14 February 2013 - 02:55 PM

When declaring a new Regex object it takes a pattern for an parameter.

 Dim r As New Regex(""".*""")



Otherwise you are trying to convert a regex class to a string.

Why do you need regex for collecting strings?

This post has been edited by _HAWK_: 14 February 2013 - 02:59 PM

Was This Post Helpful? -1
  • +
  • -

#3 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2262
  • View blog
  • Posts: 9,462
  • Joined: 29-May 08

Re: Problem Getting Strings

Posted 14 February 2013 - 02:57 PM

Quote

Otherwise you are trying to convert a regex class to a string.

Where?
Was This Post Helpful? -1
  • +
  • -

#4 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1053
  • View blog
  • Posts: 4,080
  • Joined: 02-July 08

Re: Problem Getting Strings

Posted 14 February 2013 - 03:00 PM

Their first line of code!
Was This Post Helpful? 0
  • +
  • -

#5 LilGhost  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 98
  • Joined: 12-October 12

Re: Problem Getting Strings

Posted 14 February 2013 - 03:04 PM

View Post_HAWK_, on 14 February 2013 - 02:55 PM, said:

When declaring a new Regex object it takes a pattern for an parameter.

 Dim r As New Regex(""".*""")



Otherwise you are trying to convert a regex class to a string.

Why do you need regex for collecting strings?

Whoops, didn't have my code in front of me when i posted, so i drafted something similar. Anyways, do you have a better alternative than regex?
Was This Post Helpful? 0
  • +
  • -

#6 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1053
  • View blog
  • Posts: 4,080
  • Joined: 02-July 08

Re: Problem Getting Strings

Posted 14 February 2013 - 03:05 PM

What does the text look like and what are you searching for. Please explain what you doing a little better.
Was This Post Helpful? 0
  • +
  • -

#7 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2262
  • View blog
  • Posts: 9,462
  • Joined: 29-May 08

Re: Problem Getting Strings

Posted 14 February 2013 - 03:05 PM

Dim r As New Regex = """.*"""



I see no attempted converting to a string.

This is what I see.
Dim r As New Regex = """.*"""
Error: End of Statement expected
Was This Post Helpful? 0
  • +
  • -

#8 LilGhost  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 98
  • Joined: 12-October 12

Re: Problem Getting Strings

Posted 14 February 2013 - 03:09 PM

View Post_HAWK_, on 14 February 2013 - 03:05 PM, said:

What does the text look like and what are you searching for. Please explain what you doing a little better.

Like i attempted to explain in the first post, i'm making this so you can copy and paste in a vb.net source and then in textbox it'll output every string in the source. Doing this because then i'm going to have it convert all the strings into an integer array of char values, but first priority is getting it to successfully search lengthy source.

The code itself (what i have in my source for this) isn't raising an exception, but it simply isn't finding all strings and is messing up on others.

This post has been edited by LilGhost: 14 February 2013 - 03:10 PM

Was This Post Helpful? 0
  • +
  • -

#9 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1053
  • View blog
  • Posts: 4,080
  • Joined: 02-July 08

Re: Problem Getting Strings

Posted 14 February 2013 - 03:10 PM

In attempting to assign an improper datatype you are trying to convert it - so to speak. I know your all about the explaining things to there nth degree - so just contribute!
Was This Post Helpful? 0
  • +
  • -

#10 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2262
  • View blog
  • Posts: 9,462
  • Joined: 29-May 08

Re: Problem Getting Strings

Posted 14 February 2013 - 03:12 PM

Contribute with incorrect and misleading information?
Was This Post Helpful? 0
  • +
  • -

#11 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1053
  • View blog
  • Posts: 4,080
  • Joined: 02-July 08

Re: Problem Getting Strings

Posted 14 February 2013 - 03:13 PM

This will get an array of words in a normal sentence. If your text has a specific delimiter then use that.

Dim str() As String = textbox1.Text.Split(" "c)

Was This Post Helpful? 0
  • +
  • -

#12 LilGhost  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 98
  • Joined: 12-October 12

Re: Problem Getting Strings

Posted 14 February 2013 - 03:15 PM

View Post_HAWK_, on 14 February 2013 - 03:10 PM, said:

In attempting to assign an improper datatype you are trying to convert it - so to speak. I know your all about the explaining things to there nth degree - so just contribute!



View PostAdamSpeight2008, on 14 February 2013 - 03:12 PM, said:

Contribute with incorrect and misleading information?



Not that i don't love a bit of drama, but, in an effort to keep this on track to resolve this issue faster, pretend like i didn't mistype the source and that is originally said:
dim r as new regex(""".*""")

Was This Post Helpful? 0
  • +
  • -

#13 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1053
  • View blog
  • Posts: 4,080
  • Joined: 02-July 08

Re: Problem Getting Strings

Posted 14 February 2013 - 03:18 PM

No one here can tell if you wisstype code we can only see what we see. Don't blame us for that. Did you read my post #11?
Was This Post Helpful? 0
  • +
  • -

#14 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2262
  • View blog
  • Posts: 9,462
  • Joined: 29-May 08

Re: Problem Getting Strings

Posted 14 February 2013 - 03:24 PM

A better question to ask is why are you appended in a textbox?
What do you intend to do with them (the words) once you have them?
Is it just for display?
If not then a different approach could be more beneficial.
Was This Post Helpful? 0
  • +
  • -

#15 LilGhost  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 98
  • Joined: 12-October 12

Re: Problem Getting Strings

Posted 14 February 2013 - 03:31 PM

View Post_HAWK_, on 14 February 2013 - 03:13 PM, said:

This will get an array of words in a normal sentence. If your text has a specific delimiter then use that.

Dim str() As String = textbox1.Text.Split(" "c)

not to be rude, but that is utterly useless due to the type of input that's being given.

Again, the input would be a vb.net source code so we could expect the user to paste something like:

Imports System.Net
Imports System.Text
Imports System.IO
Public Class Form1
    Dim cookieList As New List(Of System.Net.CookieContainer)
    Dim theCookie As New CookieContainer
    Dim userage As String = "Mozilla/5.0 (iPhone; U; CPU iPhone OS 5_1_1 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16"
    Dim thisPrefix As String = ""
    Dim holderBrowser As WebBrowser = New WebBrowser
   
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim postReq As HttpWebRequest = DirectCast(WebRequest.Create("http://im.wherever.com/index.php?"), HttpWebRequest)
        postReq.AllowAutoRedirect = False
        postReq.Method = "GET"
        postReq.Host = "im.wherever.com"
        postReq.KeepAlive = True
        'postReq.Referer = "http://im.wherever.com/index.php?"
        postReq.ContentType = "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"
        'MsgBox(theCookie.ToString)
        Dim tempCookie As New CookieContainer
        postReq.CookieContainer = tempCookie
        postReq.UserAgent = userage
        Dim response As HttpWebResponse = DirectCast(postReq.GetResponse, HttpWebResponse)
        Dim reader As New StreamReader(response.GetResponseStream())
        Dim home As String = reader.ReadToEnd
        If response.Headers("Set-Cookie") <> Nothing Then
            theCookie.SetCookies(New Uri("http://im.wherever.com/"), response.Headers("Set-Cookie"))
        End If
        'MsgBox(theCookie.ToString)
        RichTextBox1.Text = home
        HolderBrowser.DocumentText = home
    End Sub

    Private Sub Button3_Click() Handles Button3.Click
        ' MsgBox(theCookie.ToString)
        Dim postReq As HttpWebRequest = DirectCast(WebRequest.Create("http://im.wherever.com/hitlist.php"), HttpWebRequest)
        Dim webHeaders As WebHeaderCollection = postReq.Headers
        webHeaders.Add("Accept-Language: en-us")
        webHeaders.Add("Accept-Encoding: gzip, deflate")
        webHeaders.Add("Cache-Control: max-age=0")
        webHeaders.Add("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3")
        'webHeaders.Add("Connection: keep-alive")
        'webHeaders.Add("Cookie: " + theCookie("asc"))
        postReq.Referer = "http://im.wherever.com/home.php"
        postReq.CookieContainer = theCookie
        postReq.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
        postReq.Host = "im.wherever.com"
        postReq.KeepAlive = False
        postReq.UserAgent = userage
        postReq.AllowAutoRedirect = False
        Dim response As HttpWebResponse = DirectCast(postReq.GetResponse, HttpWebResponse)
        Dim reader As New StreamReader(response.GetResponseStream())
        Dim home As String = reader.ReadToEnd
        RichTextBox1.Text = home
        HolderBrowser.DocumentText = home
        Dim sendto As String = ""
        For Each ele As HtmlElement In HolderBrowser.document.GetElementsByTagName("a")
            If ele.GetAttribute("href").Contains("/profile.php?puid=") Then
                sendto = ele.GetAttribute("href")
                Exit For
            End If
        Next
        If sendto <> "" Then
            ' MsgBox(sendto)
            visitPuid(sendto.Split(":")(1))
        Else
            wait10.Start()
        End If
    End Sub
    Sub visitPuid(ByVal sendto As String)
        Dim postReq As HttpWebRequest = DirectCast(WebRequest.Create("http://im.wherever.com" & sendto), HttpWebRequest)
        Dim webHeaders As WebHeaderCollection = postReq.Headers
        webHeaders.Add("Accept-Language: en-us")
        webHeaders.Add("Accept-Encoding: gzip, deflate")
        webHeaders.Add("Cache-Control: max-age=0")
        webHeaders.Add("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3")
        'webHeaders.Add("Connection: keep-alive")
        'webHeaders.Add("Cookie: " + theCookie("asc"))
        postReq.Referer = "http://im.wherever.com/profile.php"
        postReq.CookieContainer = theCookie
        postReq.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
        postReq.Host = "im.wherever.com"
        postReq.KeepAlive = False
        postReq.UserAgent = userage
        postReq.AllowAutoRedirect = False
        Dim response As HttpWebResponse = DirectCast(postReq.GetResponse, HttpWebResponse)
        Dim reader As New StreamReader(response.GetResponseStream())
        Dim home As String = reader.ReadToEnd
        RichTextBox1.Text = home
        HolderBrowser.DocumentText = home
        Dim deaths As Int64 = 9999999
        If Not sendto.Contains("&selectedTab=comment") Then
            For Each ele As HtmlElement In HolderBrowser.document.GetElementsByTagName("td")
                If ele.GetAttribute("className") = "statsCol4" Then
                    deaths = CType(ele.GetAttribute("className"), Int64)
                End If
            Next
            If deaths > 1000 Then
                For Each ele As HtmlElement In HolderBrowser.document.GetElementsByTagName("a")
                    If ele.GetAttribute("href").Contains("&selectedTab=comment") Then
                        'MsgBox(sendto)
                        visitPuid(ele.GetAttribute("href").Split(":")(1))
                        Exit For
                    End If
                Next
            Else
                For Each ele As HtmlElement In HolderBrowser.document.GetElementsByTagName("input")
                    If ele.GetAttribute("value").Contains("Add to") Then
                        If HolderBrowser.DocumentText.Contains("Ajax('/bounty.php?hitlist_id=") Then
                            MsgBox((ele.GetAttribute("onclick").Split("'")(1)))
                        Else
                            MsgBox(ele.GetAttribute("href").Split(":")(1))
                        End If
                    End If
                Next
            End If
        Else

        End If
    End Sub

    Private Sub wait10_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles wait10.Tick
        wait10.Stop()
        Button3_Click()
    End Sub

End Class



and then the program needs to be able to extract the individual strings.

View PostAdamSpeight2008, on 14 February 2013 - 03:24 PM, said:

A better question to ask is why are you appended in a textbox?
What do you intend to do with them (the words) once you have them?
Is it just for display?
If not then a different approach could be more beneficial.


Whole point is to take the individual characters from inside strings only & convert them to an integer array. Each string would have its own array (array1, array2, array3, etc) that would be converted on run time into a string.

View Post_HAWK_, on 14 February 2013 - 03:18 PM, said:

No one here can tell if you wisstype code we can only see what we see. Don't blame us for that. Did you read my post #11?

#5 already said that that code was wrong and original code was modified.

This post has been edited by LilGhost: 14 February 2013 - 03:28 PM

Was This Post Helpful? -1
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2