Hello everyone, I must extract a specific part of a string within an xml, the string is in the tag and I only have to obtain the information of the dates, that is,
This is the string
PID: 209535 // COMMISSION // Provision of services from 2021-11-08 to 2021-11-14 // Pops - Express // ID: 1944
And as a result I must obtain
2021-11-08 to 2021-11-14
ppr
(Peter Preuss)
November 24, 2021, 3:36pm
2
may we ask you to share the XML with us. We want to checkout if e.g. additional specifics like namespaces are to handle. Thanks
Yes of course
Rappi.xml (9.2 KB)
ppr
(Peter Preuss)
November 24, 2021, 3:56pm
4
Your XML is defining Namespaces
implement and define namespace, done as here
Access rough and quick value like:
xDoc.Descendants(xnsDefault + "Detalle").First().Value
ppr
(Peter Preuss)
November 24, 2021, 4:00pm
5
Extraction of the dates we can use Regex:
[\d\-]+ to [\d\-]+
This CheatSheet introduces the basic use of regex functions. With further examples also special cases are presented.
Introduction
From the namespace System.Text.RegularExpressions following methods are offered:
Regex.Match
Regex.Matches
Regex.isMatch
Regex.Replace
Regex.Split
A simple usage for example would look like this:
[grafik]
Recommendation:
add System.Text.RegularExpressions to the imports:
[grafik]
it allows to use the shortened statement, as the namespace part can be ommited…
1 Like
system
(system)
Closed
November 27, 2021, 4:00pm
6
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.