EXTRAER NUMERO (AÑO) DE UNA FRASE

Buenas tardes,

He extraido de una pagina web una DT donde las columnas de los años que se extraen figuran como (ejemplos)Ejercicio 2020 Alt Text, Ejercicio 2021 Alt Text…y yo con lo que me quiero quedar es con los 4 digitos que hacen referencia al año.

No quiero poner cada año a mano, si no que quiero que este dato sea variable, ya que se solicitará cada vez un año diferente y asi no hay que hacer modificaciones a posteriori.

Gracias.

Hi @lily.RPA

Try this:

years As List(Of String) = (From column As DataColumn In YourDataTable.Columns.Cast(Of DataColumn)()
                                Let yearMatch As Match = System.Text.RegularExpressions.Regex.Match(column.ColumnName, "\d{4}")
                                Where yearMatch.Success
                                Select yearMatch.Value).ToList()

Hope it helps!!

Buenas tardes,

No lo entiendo muy bien, pero ¿se podría poner que por cada columna de esa DT, si la columna contiene el año que me pide el Excel?

Lo que no sé es cómo ponerlo.

Gracias.

Hi @lily.RPA

Pass that syntax in assign activity:

Save To: years (DataType: System.Collections.Generic.List(System.String))
Value to Save: (From column As DataColumn In YourDataTable.Columns.Cast(Of DataColumn)()
                                Let yearMatch As Match = System.Text.RegularExpressions.Regex.Match(column.ColumnName, "\d{4}")
                                Where yearMatch.Success
                                Select yearMatch.Value).ToList()

pass the datatable variable in the place of YourDataTable and the output will be of datatype List(String).
To print it in Message box or log message you can use below syntax:

String.Join(vbcrlf,years)

Hope it helps!!

Gracias por intentar ayudarme, pero ando perdida, no me entero como ponerlo