Capture only the second part of the string

Asked

Viewed 158 times

0

I have the following code to perform the method Split on a path:

Dim ItemsCopy As Integer = 0


    Dim Caminho As String = ContarItems(I)
    Dim SplitCam As String() = Regex.Split(Caminho.ToString, "=")

    For Each S As String In SplitCam

        Vizualizador.ListBox1.Items.Add(S)
    Next

Where has the ContarItems(I) is a array I put it on top just to save the URL, but it’s the following I have a URL

Exemplo: Victor\junior\Documentos\=Pasta\Teste\arquivo.teste

When I use the method it cuts straight and adds in listbox, but I wanted him to only put the second part in the case Pasta\Teste\arquivo.teste He puts the first and the second, and I don’t want that first part.

  • Looks like you’re doing something wrong.

  • Take a look at [tour]. You can accept an answer if it solved your problem. You can vote on every post on the site as well. Did any help you more? You need something to be improved?

3 answers

1

It seems that simple, but it may be that the question is not well explained. Confirm me to try to adjust or remove the answer.

Dim ItemsCopy As Integer = 0
Dim Caminho As String = ContarItems(I)
Dim SplitCam As String() = Regex.Split(Caminho.ToString, "=")
//tem que pegar um elemento específico (índice 1 é o segundo) e não varrer todo o array
Vizualizador.ListBox1.Items.Add(S(1))

I put in the Github for future reference.

  • Yes, that’s right there

  • Solved the problem? That’s exactly what you needed?

0

Consider changing your code to something that contains

Dim documentos As String = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
Dim meuArquivoDiretorio As String = "Pasta\Teste\arquivo.teste"

Dim fi = New System.IO.FileInfo(System.IO.Path.Combine(documentos, meuArquivoDiretorio))
fi.Directory.Create()

Dim FullFileName As String = fi.FullName
  • Do as I indicated above, that it will work well, and more safely.

  • Working with filenames and directories as far as I have seen does not need to use Split. Just use the Framework methods. In your case, especially Fileinfo methods

  • is but fileinfo doesn’t work the way it wanted, but thanks anyway! ^^

0

No! the function runs normally without any problem it goes exactly like this in the code, above this one has one that simply checks every line of the listbox keeps it in array and passes to another function I posted, but n wanted this first part of the string only the second part as shown in the code above.

Dim ContarItems(10) As String
    Dim I As Integer = 0
    Public Sub ExcluirArquivosDesatualizados()
        Dim contar As Integer = Vizualizador.LSTCaminho.Items.Count - 1

        For I = 0 To Vizualizador.LSTCaminho.Items.Count - 1
            Vizualizador.LSTCaminho.SelectedIndex = I

            ContarItems(I) = Vizualizador.LSTCaminho.SelectedItem.ToString
            teste()
        Next


        I = Vizualizador.LSTCaminho.Items.Count - 1
        MsgBox("0 = " & ContarItems(0).ToString & vbNewLine & _
               "1 = " & ContarItems(1))
    End Sub
  • Is this an answer or complement to the question? You speak English. It is very difficult to understand what you write.

  • kkkk.. Forget it, I’ll find a way here. But thanks for everything anyway.

  • You mean Tony’s answer solved the problem? Try to make it clear (there are edit links in your questions and answers), because the content of the site is not only read by you, but by millions of other users who may arrive at this question with the same doubt.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.