Identifying a numeric amidst string

I have a string for example “Access will be revoked in 15 minutes.” or “The sale ends in 7 days” how do i retrieve only the numeric value. (in this case - 15 & 7 respectively)

you can split the string using space like var.split(" ") then loop over it and check if the word is numeric using .isnumeric in if conditionlike currentitem.isnumeric
then assign it to variable

Hi @Sneha_Manjunath

Input = "Access will be revoked in 15 minutes"

Output = System.Text.RegularExpressions.Regex.Match(Input, "\d+").Value.Trim()

Regards

1 Like

hi @muktadir, I am looking for only the first occurrence of the numeric value, Even if there are multiple of them.

hi @vrdabberu , I am looking for only the first occurrence of the numeric value, Even if there are multiple of them.

you can break the loop in the if condition

Hi @Sneha_Manjunath

New String(inputString.SkipWhile(Function(c) Not Char.IsDigit(c)).TakeWhile(Function(c) Char.IsDigit(c)).ToArray())

Regards,

Thank you @lrtetala @vrdabberu @muktadir !

The solution provided by me will give you the first occurance only. @Sneha_Manjunath

Regards

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