Grab specific part of a Vb.net string

Asked

Viewed 25 times

0

Say hello, all right?

Can anyone give a boost? I need to capture a specific part of the string I pull from a pdf.

I needed you to capture the part of the code separated by delimiters (spaces), you know,?

Example:

Values: 2,155,85D 230,24D 11,16D 2,481,32 88,02 84,07D

I needed to capture each of these values separately, so that I could stay:

  • Value 1: 2.155,85D
  • Value 2: 230,24D
  • Value 3: 11,16

Note: This text is at the bottom of the page, so I needed it to pull from right to left, starting at the end of the string.

And so on and so forth.. Thank you guys!

1 answer

1


You can use the method Split class String with a blank space for it to search for occurrences and divide this text into parts:

Vbnet

Imports System

Module Program
    Sub Main(args As String())
    Dim texto As String = "2.155,85D 230,24D 11,16D 2.481,32 88,02 84,07D"
    Dim split As String() = texto.Split(" ")
    Console.WriteLine(split(0))
    Console.WriteLine(split(1))
    Console.WriteLine(split(2))
    Console.WriteLine(split(3))
    Console.WriteLine(split(4))
    Console.WriteLine(split(5))
    End Sub
End Module

Csharp

using System;
                    
public class Program
{
    public static void Main()
    {
        string texto = "2.155,85D 230,24D 11,16D 2.481,32 88,02 84,07D";
        string[] split = texto.Split(" ");
        Console.WriteLine(split[0]);
        Console.WriteLine(split[1]);
        Console.WriteLine(split[2]);
    }
}

recalling that a array text where each part has its own Dice that is started with 0, to know the total just use split. Length that will inform the amount of positions within this array.

  • 1

    Valeuu, I deleted the comments (I will delete this one too)

Browser other questions tagged

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