-
Apr 23rd, 2012, 07:16 PM
#1
Thread Starter
Hyperactive Member
How to split the string?
Hi guys,
Can you please help me with my code as I have a trouble with the returned strings that I have extracted from my php source to add the strings in my listview.
I'm reading the tags of mystrings1 and mystrings2 for each paragraph from the php source. I got the returned strings which it looks like this:
PHP Code:
<p id='mystrings1'>my strings</p> | <a href="http://xfvasfasfasfasf">Link</a> </td> | <a href="delete.php?id=0">Delete</a> </td> | <span id="mystrings2">Enabled</td>
I want the returned strings to be like this when I reads the tags of mystrings1 and mystrings2 while ignore the other tags.
PHP Code:
<p id='mystrings1'>my strings</p> | <span id="mystrings2">Enabled</td>
Here's the code:
Code:
Public Sub timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs)
timer1.Enabled = False
timer1.Stop()
Try
Dim URL1 As String = "http://programmingtsite.elementfx.com/myscript.php?user=test&pass=test"
Dim request1 As HttpWebRequest = CType(WebRequest.Create(URL1), HttpWebRequest)
Dim response1 As HttpWebResponse = CType(request1.GetResponse(), HttpWebResponse)
Dim reader1 As New StreamReader(response1.GetResponseStream())
Dim str1 As String = reader1.ReadToEnd()
Dim pattern1 As String = "(<p id='mystrings1'>(.*?)</p>(.*?)<span id=\"test\">(.*?)</td>)"
Dim matches1 As MatchCollection = Regex.Matches(str1, pattern1)
For Each x1 As Match In matches1
Dim StrArr1() As String = x1.Value.ToString().Split()
MessageBox.Show(x1.ToString())
Dim item1 As New ListViewItem("", 1)
item1.SubItems.Add(x1.Value.ToString().Replace("<p id='mystrings2'>", "").Replace("</p>", ""))
listView1.Items.AddRange(New ListViewItem() {item1})
listView1.CheckBoxes = True
If x1.Value.Contains("Enabled") Then
item1.Checked = True
End If
Next x1
Catch ex As Exception
End Try
End Sub
Do you know how I can ignore the other tags when I get the returned strings of mystrings1 and mystrings2??
Any advice would be much appriecated.
Thanks,
PillKilla
-
Apr 23rd, 2012, 07:21 PM
#2
Re: How to split the string?
will the 2 elements you want always be 1st + last in the returned string?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Apr 23rd, 2012, 07:24 PM
#3
Re: How to split the string?
if yes, split on "|":
dim elements() as string = returnedString.split("|"c)
1st element = elements.first
last element = elements.last
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Apr 23rd, 2012, 08:01 PM
#4
Thread Starter
Hyperactive Member
Re: How to split the string?
yes, that is what i want to split the first and the last.
however, this is invalid code:
1st element = elements.first
last element = elements.last
And Split is not a member of returnedString.
Any idea?
-
Apr 23rd, 2012, 08:42 PM
#5
Re: How to split the string?
it's pseudocode. you'll work it out...
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Apr 23rd, 2012, 08:56 PM
#6
Thread Starter
Hyperactive Member
Re: How to split the string?
I can only use x1.Split("|c"), but it said that 'Split' : is not a member of 'System::Text::RegularExpressions::Match'
Any idea?
-
Apr 23rd, 2012, 09:00 PM
#7
Re: How to split the string?
vb Code:
x1.value.tostring.Split("|"c)
.first + .last are linq extensions
*****edited*****
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Apr 25th, 2012, 03:56 PM
#8
Thread Starter
Hyperactive Member
Re: How to split the string?
i have input the .first and .last element, but they are not a member of system.text.regularexpressions.match.
Any idea?
-
Apr 25th, 2012, 04:00 PM
#9
Re: How to split the string?
Code:
Dim fields = x1.Value.ToString().Split("|"c)
Dim first = fields.First
Dim last = fields.Last
This pattern in common to all great programmers I know: they're not experts in something as much as experts in becoming experts in something.
The best programming advice I ever got was to spend my entire career becoming educable. And I suggest you do the same.
-
Apr 25th, 2012, 04:00 PM
#10
Re: How to split the string?
yep.
match is a match
.split is a member of the string class
+ .first + .last are LINQ extensions to the iEnumerable class (which includes string arrays)
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|