How to capture Numeric value from string

Hi Team,
sample string → “DESCRIPTION GROSS WT. / KG VOLUME / CBM CHG. WT. 4 DIESEL ENGINE 3143.00 9.771 3143.00 MODEL QSL CHARGES” the highlighted part is dynamic means its changing value i want to extract Gross Wt, Volume & CHG. Wt.

i have done below
Multiple Assign

PdfData–> pdfText.Replace(Environment.Newline, " “)
→ Split(pdfData,“CHG. WT.”).Last
→ pdfData.Replace(”:“,”“).Trim
→ pdfData.Substring( pdfData.IndexOf(” “c)).Trim
→ pdfData.Substring(pdfData.IndexOf(” “c)).ToString.trim
→ System.Text.RegularExpressions.Regex.Replace(pdfData,” {2,}", " ").trim
varValue–> information.IsNumeric(pdfData)

by this way i am able to extract only Gross Wt.

help to extract Volume & CHG. WT.

Hi @Ajij_Mujawar ,

Thank you letting us know the Dynamic portions of the text in advance. Also would like to know if the 4 before Diesel Engine is a dynamic part.

In addition to this Could you also let us know if you are Reading the PDF using Read PDF Text activity with PreserveFormat set to True ?

Also, Is there a possibility that one of the values would be empty or blank ?

HI @Ajij_Mujawar

How about this expression

System.Text.RegularExpressions.Regex.Matches("DESCRIPTION GROSS WT. / KG VOLUME / CBM CHG. WT. 4 DIESEL ENGINE 3143.00","(?<=\/\D*)\S+")(1)




Can you try the following?

m = System.Text.RegularExpressions.Regex.Match(yourString,"(?<GROSS>\d[\d.,]*)\D*(?<VOLUME>\d[\d.,]*)\D*(?<CHG>\d[\d.,]*)\D*$")


m.Groups("CHG").Value (2.5 KB)


Hi Arpan,
The number 4 is also dynamic, i am reading pdf by read pdf text and the values are not empty nor blank but it could be 0 value.

And i need the values in 3 variables e.g varVolume, varGrossWt, varCHG and all are type of string.

Hi @Ajij_Mujawar ,

Use @Yoichi Solution



1 Like

Thanks Yoichi

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.