tsousa Posted November 24, 2016 at 11:22 PM Report Share #600861 Posted November 24, 2016 at 11:22 PM Boa noite. Estou a criar um programa que vai buscar automaticamente os números do euromilhões, mas estou com um impasse, não consigo filtrar os números da string. Este é o meu código até agora. Imports System.Xml Public Class Form1 Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click Dim results(0 To 10) As String Dim arrpos As Integer = 0 Dim milhao As String = "Nada" ListBox4().Items.Clear() Dim xr As XmlReader = XmlReader.Create("https://www.jogossantacasa.pt/web/SCRss/rssFeedCartRes") Do While xr.Read() If xr.NodeType = XmlNodeType.Element AndAlso xr.Name = "description" Then results(arrpos) = (xr.ReadElementString) ListBox4.Items.Add(arrpos & "º " & results(arrpos)) arrpos += 1 Else xr.Read() End If Loop TextBox2.Text = results(2) TextBox3.Text = results(4) End Sub End Class Eu consegui por isto a devolver-me só a string pretendida <b>Sorteio nº 094/2016</b>: 5 10 33 34 47 + 2 10 mas queria só a parte dos números 5 10 33 34 47 + 2 10. Quando uso um split dá-me o erro "Value of type 'String()' cannot be converted to 'String'". Será que alguém me poderia dar uma ajuda? Obrigado Tiago Sousa Link to comment Share on other sites More sharing options...
vikcch Posted November 25, 2016 at 07:55 AM Report Share #600862 Posted November 25, 2016 at 07:55 AM Boas, a devolver num array de integers: Imports System.Xml Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim results(0 To 10) As String Dim arrpos As Integer = 0 Dim milhao As String = "Nada" ListBox4().Items.Clear() Dim xr As XmlReader = XmlReader.Create("https://www.jogossantacasa.pt/web/SCRss/rssFeedCartRes") Do While xr.Read() If xr.NodeType = XmlNodeType.Element AndAlso xr.Name = "description" Then results(arrpos) = (xr.ReadElementString) ListBox4.Items.Add(arrpos & "º " & results(arrpos)) arrpos += 1 Else xr.Read() End If Loop TextBox2.Text = results(2) TextBox3.Text = results(4) Dim numbers() As Integer = GetNumbers(results(2)) If numbers.Length = 7 Then For Each n As Integer In numbers MessageBox.Show(n.ToString()) Next Else MessageBox.Show("problemas!") End If End Sub Private Function GetNumbers(ByVal str As String) As Integer() Dim strArray() As String = str.Split(New String() {"</b>:"}, StringSplitOptions.None) If strArray.Length = 2 Then Dim strNumbers As String = strArray(1).Replace("+ ", "").Trim() Return Array.ConvertAll(strNumbers.Split(" "), AddressOf Int32.Parse) End If Return New Integer() {} End Function End Class 1 Report Link to comment Share on other sites More sharing options...
tsousa Posted November 25, 2016 at 04:21 PM Author Report Share #600872 Posted November 25, 2016 at 04:21 PM Funciona obrigado 🙂 Link to comment Share on other sites More sharing options...
tsousa Posted November 25, 2016 at 05:34 PM Author Report Share #600874 Posted November 25, 2016 at 05:34 PM Já agora podes-me ajudar para me devolver o valor do milhao (results(4)) por favor. Link to comment Share on other sites More sharing options...
vikcch Posted November 26, 2016 at 02:55 PM Report Share #600881 Posted November 26, 2016 at 02:55 PM (edited) Tentaste fazer? É quase igual mas mais simples ainda... no botão: Dim m1lhao As String = GetMilhao(results(4)) If Not String.IsNullOrEmpty(m1lhao) Then MessageBox.Show(m1lhao) Else MessageBox.Show("problemas!") End If a função: Private Function GetMilhao(ByVal str As String) As String ' divide a string quando acha a cadeia de caracteres "</b>:" Dim strArray() As String = str.Split(New String() {"</b>:"}, StringSplitOptions.None) ' verifica se o array tem dois elementos If strArray.Length = 2 Then ' retorna o conteudo do ultimo elemento do array (podias usar "strArray.Last()") ' o "trim()" remove os spaces " " das pontas Return strArray(1).Trim() End If Return String.Empty End Function Edited November 26, 2016 at 02:56 PM by vikcch 1 Report Link to comment Share on other sites More sharing options...
tsousa Posted December 2, 2016 at 11:18 AM Author Report Share #600978 Posted December 2, 2016 at 11:18 AM (edited) Tentei mas não consegui. Obrigado, e obrigado também por teres posto comentários, isso ajuda-me bastante a entender o código Edited December 2, 2016 at 11:19 AM by tsousa Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now